在本机反应中检测静音模式

时间:2019-03-11 14:47:49

标签: react-native

是否有任何方法可以知道电话(iPhoneAndroid)是否使用react-native处于静音模式?

1 个答案:

答案 0 :(得分:0)

我发现library帽子有getVolume()方法来检索设备体积。它具有大量其他功能,因此拥有大型图书馆。

如果您只是想获取状态,请尝试自己编写本机模块。 Android具有 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;
}

iOS则参考[this]实现(Detect silent mode in iOS 7

祝你好运:)

相关问题