在之前的一些android版本中,修改默认音量是修改:

path:frameworks\base\media\java\android\media\AudioService.java

    /// M: modify the default stream volume @{    public static int[] DEFAULT_STREAM_VOLUME = new int[] {        4,   // STREAM_VOICE_CALL        8,  // STREAM_SYSTEM        8,   // STREAM_RING        8,   // STREAM_MUSIC        8,   // STREAM_ALARM        8,   // STREAM_NOTIFICATION        8,   // STREAM_BLUETOOTH_SCO        8,  // STREAM_SYSTEM_ENFORCED        8,  // STREAM_DTMF        8,  // STREAM_TTS        8  // STREAM_ACCESSIBILITY    };    /// @}

当然此文件中也定义了Volume的最大值和最小值:

   /** Maximum volume index values for audio streams */    /// M: Modify the max stream volume @{    protected static int[] MAX_STREAM_VOLUME = new int[] {        7,   // STREAM_VOICE_CALL        15,  // STREAM_SYSTEM        15,  // STREAM_RING        15,  // STREAM_MUSIC        15,  // STREAM_ALARM        15,  // STREAM_NOTIFICATION        15,  // STREAM_BLUETOOTH_SCO        15,  // STREAM_SYSTEM_ENFORCED        15,  // STREAM_DTMF        15,  // STREAM_TTS        15   // STREAM_ACCESSIBILITY    };    /** Minimum volume index values for audio streams */    protected static int[] MIN_STREAM_VOLUME = new int[] {        1,  // STREAM_VOICE_CALL        0,  // STREAM_SYSTEM        0,  // STREAM_RING        0,  // STREAM_MUSIC        1,  // STREAM_ALARM        0,  // STREAM_NOTIFICATION        0,  // STREAM_BLUETOOTH_SCO        0,  // STREAM_SYSTEM_ENFORCED        0,  // STREAM_DTMF        0,  // STREAM_TTS        1   // STREAM_ACCESSIBILITY    };

OK  回归主题,在android Q版本中DEFAULT_STREAM_VOLUME数组的定义是在AudioSystem.java文件中,但是修改这个数组中的值发现还是无法正确处理为自己想要的默认值。

发现初始化默认值是在AudioService.java的AudioService()方法中:

        int maxCallVolume = SystemProperties.getInt("ro.config.vc_call_vol_steps", -1);        if (maxCallVolume != -1) {            MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = maxCallVolume;        }        int defaultCallVolume = SystemProperties.getInt("ro.config.vc_call_vol_default", -1);        if (defaultCallVolume != -1 &&                defaultCallVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] &&                defaultCallVolume >= MIN_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]) {            AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] = defaultCallVolume;        } else {            AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL] =                    (maxCallVolume * 3) / 4;        }        int maxMusicVolume = SystemProperties.getInt("ro.config.media_vol_steps", -1);        if (maxMusicVolume != -1) {            MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = maxMusicVolume;        }        int defaultMusicVolume = SystemProperties.getInt("ro.config.media_vol_default", -1);        if (defaultMusicVolume != -1 &&                defaultMusicVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] &&                defaultMusicVolume >= MIN_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]) {            AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] = defaultMusicVolume;        } else {            if (isPlatformTelevision()) {                AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] =                        MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] / 4;            } else {                AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] =                        MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC] / 3;            }        }        int maxAlarmVolume = SystemProperties.getInt("ro.config.alarm_vol_steps", -1);        if (maxAlarmVolume != -1) {            MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM] = maxAlarmVolume;        }        int defaultAlarmVolume = SystemProperties.getInt("ro.config.alarm_vol_default", -1);        if (defaultAlarmVolume != -1 &&                defaultAlarmVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM]) {            AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_ALARM] = defaultAlarmVolume;        } else {            // Default is 6 out of 7 (default maximum), so scale accordingly.            AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_ALARM] =                        6 * MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM] / 7;        }        int maxSystemVolume = SystemProperties.getInt("ro.config.system_vol_steps", -1);        if (maxSystemVolume != -1) {            MAX_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM] = maxSystemVolume;        }        int defaultSystemVolume = SystemProperties.getInt("ro.config.system_vol_default", -1);        if (defaultSystemVolume != -1 &&                defaultSystemVolume <= MAX_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM]) {            AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM] = defaultSystemVolume;        } else {            // Default is to use maximum.            AudioSystem.DEFAULT_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM] =                        MAX_STREAM_VOLUME[AudioSystem.STREAM_SYSTEM];        }

发现这些初始化的值都是由一些ro.config.属性控制的,所以要修改默认音量大小,可以直接客制化ro.config.这些属性值就OK。

更多相关文章

  1. android软件音量控制
  2. Android 初始化之Zygote
  3. Android init language (安卓初始化语言)
  4. android保存第一次安装状态并初始化数据
  5. Android tips tool 发现的性能问题
  6. Android音量调节
  7. Android 音量调节

随机推荐

  1. RotateAnimation 设置旋转中心点、不停顿
  2. Android:为控件绑定监听器
  3. 申请Android Maps API Key-及出现的错误
  4. 什么是aidl?Android(安卓)AIDL详解
  5. Android Ams浅析
  6. Android 实现直接拒接来电
  7. Android:控件布局(相对布局)RelativeLayout
  8. android ICS4.0.3 改变默认字体大小
  9. android带动画的圆形进度条
  10. android 设置界面