This article was reproduced from: http://blog.csdn.net/a8316124/article/details/60574859
When doing custom requirements, you need to modify the sound of the system notification, disable it, to avoid the third-party application to send notifications, the sound is very loud, scare users. Simply turn off the notification sound. Let's talk about several ways to turn off sound, and how to modify the system default sound.
1. Directly modify the default sound size of the system layer
Two arrays are defined at the beginning of the system code frameworks/base/media/java/android/media/AudioService.java
, one of MAX_STREAM_VOLUME
which defines the maximum of various sounds (the maximum value is not 100, so you need AudioManager.getStreamMaxVolume(type)
to get the maximum of each volume) and then set it up.
Also defines an array DEFAULT_STREAM_VOLUME
where the surface is the MAX_STREAM_VOLUME
same as defined in the order, indicating the default size of the various sounds. This block code is as follows:
/** @hide Maximum Volume index values for audio streams */PrivateStaticint[] Max_stream_volume =NewInt[] {5,Stream_voice_call7,Stream_systemx_stream_volumemax_stream_volumemax_stream_volume7,Stream_ring15,Stream_music7,Stream_alarm7,Stream_notification15,Stream_bluetooth_sco7,stream_system_enforced15,Stream_dtmf15Stream_tts};PrivateStaticint[] Default_stream_volume =new int[] {4, //stream_voice_call 7, //STREAM_SYSTEM 5, //stream_ring 11, //stream_music 6, //STREAM_ALARM 5, //stream_notification 7, //Stream_bluetooth_sco 7, //STREAM_SYSTEM_ ENFORCED 11, //stream_dtmf 11 //Stream_tts};
If we need to change the default notification sound, we can STREAM_NOTIFICATION
give the previous value 5 to 0, so the default sound is 0.
2. Modify notification sound values in the database
Media Voice This data is stored by default in the database, and we know that most of the data is the initial boot of the system when the SettingProvider
initialized value is loaded in the application, of course, the sound of the notification is also inside.
The specific code in frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
which there is a method loadVolumeLevels(db)
This method is the place to load all default sound sizes, as follows:
stmt = Db.compilestatement ("INSERTORIGNOREIntoSystemname,value) "+" values (?,?);"); Loadsetting (stmt, Settings.System.VOLUME_MUSIC, Audioservice.getdefaultstreamvolume (Audiomanager.stream_music)); Loadsetting (stmt, Settings.System.VOLUME_RING, Audioservice.getdefaultstreamvolume (audiomanager.stream_ring)); Loadsetting (stmt, Settings.System.VOLUME_SYSTEM, Audioservice.getdefaultstreamvolume (Audiomanager.stream_system) ); Loadsetting (Stmt,settings.system.volume_voice,audioservice.getdefaultstreamvolume (AudioManager.STREAM_VOICE_ Call); Loadsetting (stmt, Settings.System.VOLUME_ALARM, Audioservice.getdefaultstreamvolume (AUDIOMANAGER.STREAM_ ALARM)); Loadsetting (Stmt,settings.system.volume_notification,audioservice.getdefaultstreamvolume ( audiomanager.stream_notification)); Loadsetting (Stmt,settings.system.volume_bluetooth_sco, Audioservice.getdefaultstreamvolume (Audiomanager.stream_bluetooth_sco));
We found that all sound-related default values are written to the database in loadsetting, then we can start from here, in Settings.System.VOLUME_NOTIFICATION
the settings we set him to 0, the system notifies the default sound is 0, we look at the AudioService.getDefaultStreamVolume
implementation of this method.
Getdefaultstreamvolume(return default_stream_volume[streamtype];}
The actual return is the value of the default volume size array inside the system in scenario one. So programme I and Programme II are actually an effect
3. Modifying the Ro.config.notification_sound property values
This property value means to notify the default music file filename, we defined in the system code build/target/product/full_base.mk
, if we do not want to have a sound then we can change the default value to a nonexistent file, the notification sound will not play, of course, we can also use in customer-defined MK PRODUCT_PROPERTY_OVERRIDES
to replicate this property, Designate it as a nonexistent file or null so that no notification sound is heard.
4. Modify the default sound
The system default a lot of sound, then we have to modify some of the system's default sound files, then we can modify the frameworks/base/data/sounds
following files and folders in the sound file, if changed the name remember to replace the original in the MK with a new name. The role of the following MK is to all of these music files packaged into system/media/audio
the system under the various modules of the file, and then when the system boot, scan the files, add them to the database, and then change the sound in the settings, then directly from the database to query the music files, and then for the user to choose.
Summarize
System of media this piece is very heavy also very big piece, here is only a little fur, just use to find out, want to system system study still need to study a lot of work. If you have any questions, please leave feedback.
Android default system sound/size modification and Configuration "Go"