react-native - 在本机反应中检测静音模式
问题描述
有什么方法可以使用 react-native知道手机(iPhone
或)是否处于静音模式?Android
解决方案
我发现一个库帽有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] implementation(在 iOS 7 中检测静默模式)
祝你好运 :)