如何在 android 中以编程方式增加铃声和通知音量

How to increase the ringer & notification volume programmatically in android

我正在尝试启用铃声正常模式并以编程方式增加音量。

AudioManager mobilemode = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
//   int streamMaxVolume = mobilemode.getStreamMaxVolume(AudioManager.STREAM_RING);
switch (mobilemode.getRingerMode()) {
    case AudioManager.RINGER_MODE_SILENT:
        Log.i("MyApp","Silent mode");

        mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        mobilemode.setStreamVolume (AudioManager.STREAM_MUSIC,mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);
        break;
    case AudioManager.RINGER_MODE_VIBRATE:
        Log.i("MyApp","Vibrate mode");                     
        mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        mobilemode.setStreamVolume (AudioManager.STREAM_MUSIC,mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        Log.i("MyApp","Normal mode");
        break;
}

但是它启用了普通模式。但我无法增加音量。

请让我以编程方式增加音量..

替换行

mobilemode.setStreamVolume (AudioManager.STREAM_MUSIC,mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);

下划线

mobilemode.setStreamVolume(AudioManager.STREAM_RING,audioManager.getStreamMaxVolume(AudioManager.STREAM_RING),0);