如何仅静音来电铃声而不静音短信

时间:2019-06-26 21:14:38

标签: java android android-audiomanager

如何仅使来电铃声静音而不使短信静音,并且仅使短信静音?

我尝试像使用audioManager.setStreamVolume()

audioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
switch (mode){
               case CALLS:
                   audioManager.setStreamVolume(AudioManager.STREAM_RING,AudioManager.ADJUST_MUTE,0);
                   break;
               case MSGS:
                   audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,AudioManager.ADJUST_MUTE,0);
                   break;
               case CALLS_AND_MSGS:
                   audioManager.setStreamVolume(AudioManager.STREAM_RING,AudioManager.ADJUST_MUTE,0);
                   audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,AudioManager.ADJUST_MUTE,0);
                   break;

           }

在所有情况下,来电和短信均处于静音状态

1 个答案:

答案 0 :(得分:0)

您需要使用以下代码行

audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);