音量加减键修改为默认控制媒体音量

默认是控制Ringer volume。
frameworks/base/core/res/res/values/strings.xml:    <string name="volume_ringtone">Ringer volume</string>

    <!-- Title of the dialog where the user is adjusting the phone ringer volume -->
    <string name="volume_ringtone">Ringer volume</string>
    <!-- Title of the dialog where the user is adjusting the music volume -->
    <string name="volume_music">Media volume</string>

frameworks/base/core/java/android/view/VolumePanel.java:    private static final int RINGTONE_VOLUME_TEXT = com.android.internal.R.string.volume_ringtone;
case AudioManager.STREAM_RING:
case AudioManager.STREAM_MUSIC:
            case MSG_VOLUME_CHANGED: {
                onVolumeChanged(msg.arg1, msg.arg2);
                break;
            }
public void postVolumeChanged(int streamType, int flags)
frameworks/base/media/java/android/media/AudioService.java:        mVolumePanel.postVolumeChanged(streamType, flags);
public void setStreamVolume(int streamType, int index, int flags)
public void adjustStreamVolume(int streamType, int direction, int flags)
public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags)
public void adjustVolume(int direction, int flags)
AudioManager.USE_DEFAULT_STREAM_TYPE
private int getActiveStreamType(int suggestedStreamType)
        } else if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {
            // Log.v(TAG, "getActiveStreamType: Forcing STREAM_RING...");
            //jeff. return AudioSystem.STREAM_RING; 
            return AudioSystem.STREAM_MUSIC;
        } else {


修改后就是默认媒体音量了。

其原理就是将按键所对应的默认音频数据流从来电数据流改为音乐数据流:
AudioManager.USE_DEFAULT_STREAM_TYPE) {
            // Log.v(TAG, "getActiveStreamType: Forcing STREAM_RING...");
            //jeff. return AudioSystem.STREAM_RING; 
            return AudioSystem.STREAM_MUSIC;
        } else {


你可能感兴趣的:(String,Stream,user,dialog,音乐)