首页 > 解决方案 > 在本机反应中检测静音模式

问题描述

有什么方法可以使用 react-native知道手机(iPhone或)是否处于静音模式?Android

标签: react-native

解决方案


我发现一个帽有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 中检测静默模式

祝你好运 :)


推荐阅读