Android:飞行模式是完全关闭 radio 还是只关闭传输部分?

标签 android bluetooth airplane-mode

我有一个同时使用 ble 和 wifi 的 Android 应用程序。定期 ble 锁定并且不再检测设备。在查找锁定故障时,我注意到我可以通过关闭飞行/飞行模式来恢复正常操作。但是,如果我打开/关闭蓝牙或打开/关闭 wifi,或者打开/关闭 wifi 和蓝牙,我无法复制通过打开/关闭飞行模式获得的结果。这告诉我飞行模式正在做一些不同的事情。所以:

飞行模式与打开和关闭蓝牙和/或 wifi 的单独功能有什么区别?

最佳答案

我们知道什么

飞行模式会禁用所有 radio 、蜂窝、蓝牙、GPS、NFC、wimax 以及 Settings.Global.AIRPLANE_MODE_RADIOS 中声明的任何其他 radio 您可以通过执行 adb shell settings get global airplane_mode_radios 检查您特定设备中的列表。

我们不知道的事

至于为什么它与简单地自行禁用某些 radio 不同,我也遇到过类似的情况,WIFI 在飞行模式ON/OFF 后不再连接并再次工作。

可以关注source code of what APM does但最后它作为用户广播了 Intent Intent.ACTION_AIRPLANE_MODE_CHANGED 并且这个 Intent 由 radio 的所有广播接收器单独处理。 他们处理此问题的方式与在设置中简单切换 radio 不同,这决定了它是否恢复正常。

深入挖掘

例如,在 BluetoothManagerService ,当我们启用飞行模式时,我们触发 radio 的状态 2,而不是将被禁用的 0。因此,禁用飞行模式禁用 之间显然存在区别,这很有趣。

// Bluetooth persisted setting is off
private static final int BLUETOOTH_OFF=0;
// Bluetooth persisted setting is on
// and Airplane mode won't affect Bluetooth state at start up
private static final int BLUETOOTH_ON_BLUETOOTH=1;
// Bluetooth persisted setting is on
// but Airplane mode will affect Bluetooth state at start up
// and Airplane mode will have higher priority.
private static final int BLUETOOTH_ON_AIRPLANE=2;

如您所见,在 Manager 的源代码中,注意到飞行模式会影响启动。所以也许这就是你所追求的。当我们在飞行模式后启用 radio 时,这是运行的代码:

sendEnableMsg(mQuietEnableExternal);

但是,只需启用 radio 即可运行此程序: sendEnableMsg(假);

结论

可能跟安静模式有关?这相当吸引人,很抱歉我无法提供更好的答案,但如果您想更深入地挖掘,希望这是一个很好的起点。

关于Android:飞行模式是完全关闭 radio 还是只关闭传输部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36556201/

相关文章:

android - 向 XML 添加自定义 View ...但具有通用类型

c - 将 Gatttool 命令/请求转换为 Bluez c

audio - 为什么Chromecast v2具有蓝牙功能,如何连接蓝牙?

ios - 使用 Mac 数据包记录器进行蓝牙 LE 跟踪

ios - iOS 8 上的可达性延迟?

iphone - UI iOS 自动化 : I want to background the app and click the settings panel to put the phone into airplane mode to test the apps offline behaviour

android - 如何使用 adb 在 android 上启用飞行模式

android - 启动另一个 Activity 的 Activity 模式(用于结果)

android - RadioGroup 无法正常工作

android - 如何在 iOS 和 android 中实现 YouTube LiveStream 播放器?