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.
try this:
switch( audio.getRingerMode() ){
case AudioManager.RINGER_MODE_NORMAL:
break;
case AudioManager.RINGER_MODE_SILENT:
break;
case AudioManager.RINGER_MODE_VIBRATE:
break;
}
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;
}