How to increase the ringer & notification volume programmatically in android

和自甴很熟 提交于 2019-12-30 04:57:12

问题


I am trying to enable the ringer normal mode and increase the volume programmatically.

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;
}

But It enable the normal mode. But I can not increase the volume.

Please let me any way to increase the volume programmatically..


回答1:


Replace the line

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

with below line

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


来源:https://stackoverflow.com/questions/30432758/how-to-increase-the-ringer-notification-volume-programmatically-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!