在 React Native 中检测静默模式

Hai*_*luf 5 react-native

有没有办法使用react-native知道手机(iPhoneAndroid)是否处于静音模式?

Fir*_*iru 1

我发现图书馆帽子有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;
}
Run Code Online (Sandbox Code Playgroud)

而对于 iOS,请参考 [this] 实现(在 iOS 7 中检测静音模式

祝你好运 :)