5

Is there any way to know if phone (iPhone or Android) is in silent mode using react-native?

YosiFZ
  • 7,792
  • 21
  • 114
  • 221
Hai Alaluf
  • 757
  • 7
  • 15

1 Answers1

1

I found a library hat has getVolume() method to retrieve the device volume. It has tons of other features so its big library.

If you just wanted to get the status try writing native modules yourself. Android has AudioManager class

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

whereas for iOS refer [this] implementation(Detect silent mode in iOS 7)

Good luck :)

Firdous nath
  • 1,487
  • 1
  • 14
  • 38