以编程方式启用飞行模式不会禁用移动数据和蓝牙
我想通过代码打开飞行模式并关闭蓝牙、wifi和移动数据。 首先,在控制台中执行此操作:
adb shell pm grant com.package.name android.permission.WRITE_SECURE_SETTINGS
其次,从代码中打开飞行模式:
//Set radios cell,wifi,bluetooth witch will be off
Settings.Global.putString(requireContext().contentResolver,
Settings.Global.AIRPLANE_MODE_RADIOS,
"${Settings.Global.RADIO_CELL},
${Settings.Global.RADIO_WIFI},
${Settings.Global.RADIO_BLUETOOTH}"
)
Settings.Global.putInt(
requireContext().contentResolver,
Settings.Global.AIRPLANE_MODE_ON, 1
)
但在设置中,我看到只有 wifi 被关闭,蓝牙和移动日期仍然打开。为什么我不能通过代码将它们全部关闭?
I want to turn on airplane mode through the code and turn off bluetooth, wifi and mobile data.
First, execute this in the console:
adb shell pm grant com.package.name android.permission.WRITE_SECURE_SETTINGS
Second, turn on airplane mode from code:
//Set radios cell,wifi,bluetooth witch will be off
Settings.Global.putString(requireContext().contentResolver,
Settings.Global.AIRPLANE_MODE_RADIOS,
"${Settings.Global.RADIO_CELL},
${Settings.Global.RADIO_WIFI},
${Settings.Global.RADIO_BLUETOOTH}"
)
Settings.Global.putInt(
requireContext().contentResolver,
Settings.Global.AIRPLANE_MODE_ON, 1
)
But in the settings, I see that only wifi is turned off, bluetooth and mobile date are still on. Why can't I turn them all off from the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,一些 Android 制造商需要使用 Settings.Secure 而不是 Settings.Global。通过命令检查
其次,您应该尝试通知系统您的更改。
此意图有一个参数,几乎不需要在每个设备上使用来通知特定的飞机状态(1 - 打开,0 - 关闭):
First of all, some android manifactures require usage of Settings.Secure instead of Settings.Global. Check it via command
Second of all, you should try to notify system about your changes.
There is parameter for this intent that is unneccessary to use on almost every device to notify specific airplane state (1 - ON, 0 - OFF):