66

How to identify whether the phone is in Silent mode or not?

I am using Android 1.5. I tried by using "android.provider.Settings.ACTION_SOUND_SETTINGS". It is not working.

Cœur
  • 34,719
  • 24
  • 185
  • 251
Raghu
  • 2,229
  • 6
  • 23
  • 21

2 Answers2

161

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;
}
Dave Webb
  • 185,507
  • 57
  • 307
  • 296
  • Hi Dave is there any way to toggle Silent as well as vibrating mode programatically. – Vinayak Bevinakatti Jan 12 '10 at 13:23
  • 4
    `setRingerMode()` in `AudioManager` allows you to change the ringer mode. – Dave Webb Jan 12 '10 at 13:34
  • 1
    Hi Dave I can able to handle the silent mode using am.setRingerMode(AudioManager.RINGER_MODE_SILENT); but handling Vibrating mode using AudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF); is not working any clue – Vinayak Bevinakatti Jan 12 '10 at 14:26
  • What is it that you're trying to do exactly? I don't think `setVibrateSettings()` does what you think it does. – Dave Webb Jan 12 '10 at 14:32
1

Following code checks if phone is not in silent mode then plays a beep, written in kotlin:

    val manager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
    manager.setStreamVolume(AudioManager.STREAM_MUSIC, 10, 0)
    val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
    val player: MediaPlayer = MediaPlayer.create(applicationContext, notification)
    if(manager.ringerMode != AudioManager.RINGER_MODE_SILENT)
        player.start()
Mohsen Emami
  • 1,756
  • 2
  • 24
  • 34