How to Detect Whether the Android Phone in Silent Mode Programmatically

how can I detect whether the android phone in Silent mode programmatically

Use the getRingerMode() method in AudioManager.

AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
Log.i("MyApp","Silent mode");
break;
case AudioManager.RINGER_MODE_VIBRATE:
Log.i("MyApp","Vibrate mode");
break;
case AudioManager.RINGER_MODE_NORMAL:
Log.i("MyApp","Normal mode");
break;
}

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

try this:

switch( audio.getRingerMode() ){
case AudioManager.RINGER_MODE_NORMAL:
break;
case AudioManager.RINGER_MODE_SILENT:
break;
case AudioManager.RINGER_MODE_VIBRATE:
break;
}

Design an application that sets the device in silent mode at a specified time

How to make the application knows that the time has come to make the
phone silent (when the application is closed)

One word: AlarmManager

how to make the application works and converts the phone to silent
mode when the time comes

The AlarmManager mentionned above will launch your app at the set up time. To silence the phone, check the following question: Automatically silence the sound volume of Android Phone programmatically?

Is it possible to turn off the silent mode programmatically in android?

Solution for you .

AudioManager am;
am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);

//For Normal mode
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

//For Silent mode
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);

//For Vibrate mode
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);


Related Topics



Leave a reply



Submit