修改系统默认音量需要改两处地方:
1. frameworksasemediajavaandroidmediaAudioManager.java
1 /** @hide Default volume index values for audio streams */ 2 public static final int[] DEFAULT_STREAM_VOLUME = new int[] { 3 4, // STREAM_VOICE_CALL 4 7, // STREAM_SYSTEM 5 5, // STREAM_RING 6 8,//11, // STREAM_MUSIC 7 6, // STREAM_ALARM 8 5, // STREAM_NOTIFICATION 9 7, // STREAM_BLUETOOTH_SCO 10 7, // STREAM_SYSTEM_ENFORCED 11 11, // STREAM_DTMF 12 11, // STREAM_TTS 13 4 // STREAM_INCALL_MUSIC 14 };
此处的音量值用来生成settings.db数据库字段的值。settings.db数据库在Android 5.x中的路径为/data/data/com.android.providers.settings/database/目录下。
2. frameworksasemediajavaandroidmediaAudioService.java
1 /** @hide Maximum volume index values for audio streams */ 2 private static int[] MAX_STREAM_VOLUME = new int[] { 3 15, // STREAM_VOICE_CALL 4 7, // STREAM_SYSTEM 5 7, // STREAM_RING 6 15, // STREAM_MUSIC 7 7, // STREAM_ALARM 8 7, // STREAM_NOTIFICATION 9 15, // STREAM_BLUETOOTH_SCO 10 7, // STREAM_SYSTEM_ENFORCED 11 15, // STREAM_DTMF 12 15 // STREAM_TTS 13 }; 14 15 private static int[] DEFAULT_STREAM_VOLUME = new int[] { 16 15, // STREAM_VOICE_CALL 17 7, // STREAM_SYSTEM 18 5, // STREAM_RING 19 8,//11, // STREAM_MUSIC 20 6, // STREAM_ALARM 21 5, // STREAM_NOTIFICATION 22 7, // STREAM_BLUETOOTH_SCO 23 7, // STREAM_SYSTEM_ENFORCED 24 11, // STREAM_DTMF 25 11 // STREAM_TTS 26 };
MAX_STREAM_VOLUME 数组为系统最大音量值。
DEFAULT_STREAM_VOLUME 数组为系统默认音量值。