How to check if phone is mute, vibrate or loud in android

后端 未结 2 2110
执念已碎
执念已碎 2020-12-25 12:02

This is my code to mute/unmute phone. But I would like to check if phone is alreay on mute and if is not then i will mute it. If is in vibrate then i will make it normal.

相关标签:
2条回答
  • 2020-12-25 12:20

    try this:

    switch( audio.getRingerMode() ){
    case AudioManager.RINGER_MODE_NORMAL:
       break;
    case AudioManager.RINGER_MODE_SILENT:
       break;
    case AudioManager.RINGER_MODE_VIBRATE:
       break;
    }
    
    0 讨论(0)
  • 2020-12-25 12:29

    In my case I found out that even if my phone settings is to vibrate, it will return AudioManager.RINGER_MODE_SILENT when is it silence, so I found a way to check the vibration mode if then:

    public static boolean checkVibrationIsOn(Context context){
        boolean status = false;
        AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
        if(am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE){
            status = true;
        } else if (1 == Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0)) //vibrate on
            status = true;
        return status;
    }
    

    And to get the whole picture, to find out if ringer is on:

    public static boolean checkRingerIsOn(Context context){
        AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
        return am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL;
    }
    
    0 讨论(0)
提交回复
热议问题