Is it possible to turn off the silent mode programmatically in Android?
Asked
Active
Viewed 2.9k times
28
-
@Mat, well, that question was for iPhone, this is for android. I doubt the answers to that question is helpful to the op. – aioobe Jul 28 '12 at 08:57
5 Answers
66
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);

Chirag
- 56,621
- 29
- 151
- 198
-
3Is this answer still valid in 2013? I thought I read that this is no longer viable per some recent update. – temporary_user_name Sep 25 '13 at 02:14
-
2
-
1Working in smasung, nexus, moto devices. bit not working on xiomi devices. any idea how to achieve in xiomi devices. – Abhi Oct 12 '16 at 06:05
-
hello abhi....did you achieve it on xiomi devices?? if yes then please tell me. @Abhi – Jaydip Kalkani Mar 04 '18 at 14:50
-
-
You can try [this](https://stackoverflow.com/a/39152607/7804719). @Abhi – Jaydip Kalkani Mar 19 '18 at 13:40
-
-
2A little update: as per documentation "From N onward, ringer mode adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access." -> which means you can't change Silent mode without asking for DnD permission. – E.Akio Mar 18 '21 at 13:04
10
//SilentToNomal and NormalToSilent device Programatically
final AudioManager mode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
//Silent Mode Programatically
mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
//Normal Mode Programatically
mode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

Aditya Gupta
- 29
- 4

patel
- 830
- 1
- 11
- 26
6
Solution:
AudioManager audio_mngr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
audio_mngr .setRingerMode(AudioManager.RINGER_MODE_SILENT);

Paresh Mayani
- 127,700
- 71
- 241
- 295
-
how to make it reverse, after silent mode how to set back to normal mode. – sandy May 07 '13 at 10:43
-
@sandy try RINGER_MODE_NORMAL (http://developer.android.com/reference/android/media/AudioManager.html#RINGER_MODE_NORMAL) for it? – Aman Alam Oct 05 '14 at 08:02
0
Yes this is possible to turn off and on the silent mode programmatically below is the code :
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
for setting silent mode :
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
For normal mode :
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

Antonio Pérez
- 6,702
- 4
- 36
- 61

Arun kumar
- 1,894
- 3
- 22
- 28
0
int normal = 2;
int vibrate = 1;
int silent = 0;
int RingerMode;
public static AudioManager AUDIOMANAGER;
@Override
public void onCreate() {
super.onCreate();
AUDIOMANAGER= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
if (AUDIOMANAGER.getRingerMode() == normal) {
AUDIOMANAGER.setRingerMode(AudioManager.RINGER_MODE_SILENT);
RingerMode = normal;
} else if (AUDIOMANAGER.getRingerMode() == vibrate) {
AUDIOMANAGER.setRingerMode(AudioManager.RINGER_MODE_SILENT);
RingerMode = vibrate;
}
//And after do all your jobs..... you can return to previous mode:
AUDIOMANAGER.setRingerMode(RingerMode);
}

Iman Marashi
- 5,593
- 38
- 51