28

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

1
  • @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, 2012 at 8:57

5 Answers 5

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);
8
  • 3
    Is this answer still valid in 2013? I thought I read that this is no longer viable per some recent update. Sep 25, 2013 at 2:14
  • 2
    Hello? Can I get an answer here? Feb 28, 2014 at 5:05
  • 1
    Working in smasung, nexus, moto devices. bit not working on xiomi devices. any idea how to achieve in xiomi devices.
    – Abhi
    Oct 12, 2016 at 6:05
  • hello abhi....did you achieve it on xiomi devices?? if yes then please tell me. @Abhi Mar 4, 2018 at 14:50
  • 2
    A 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, 2021 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);
6

Solution:

AudioManager audio_mngr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
audio_mngr .setRingerMode(AudioManager.RINGER_MODE_SILENT);
2
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);

}
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);

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.