我正在尝试使用命令行在Android设备上启用禁用蓝牙。
我可以使用它
adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
但它会提示用户“允许”或“拒绝”。
我也看到有一个选项可以首先启动ble设置
adb shell am start -a android.settings.BLUETOOTH_SETTINGS
然后启用禁用adb shell input keyevent **
但它不会与设备无关。
启用:
adb shell service call bluetooth_manager 6
要禁用:
adb shell service call bluetooth_manager 8
要运行先前注释中列出的命令,您需要是root:
adb root
启用:
adb shell service call bluetooth_manager 6
禁用:
adb shell service call bluetooth_manager 8
启用:
adb shell service call bluetooth_manager 6
要禁用:
adb shell service call bluetooth_manager 9
测试并使用三星Galaxy S7。
对于蓝牙状态:
adb shell settings get global bluetooth_on
要么
adb shell settings list global |grep ^bluetooth_on
启用蓝牙
adb shell settings put global bluetooth_on 1
禁用蓝牙
adb shell settings put global bluetooth_on 0
通过上午 - 使用启用而不是请求
adb shell am broadcast -a android.intent.action.BLUETOOTH_ENABLE --ez state true
通过Keyevents
adb shell am start -a android.settings.BLUETOOTH_SETTINGS
adb shell input keyevent 19
adb shell input keyevent 23
最后想出了一种在Android 8.0和没有root的新版本上打开/关闭蓝牙的方法,“bluetooth_on”似乎不再适用于最新的Android版本:
启用蓝牙 - 无需root
adb shell settings put global bluetooth_disabled_profiles 1
禁用蓝牙 - 无需root
adb shell settings put global bluetooth_disabled_profiles 0
并且由于上面工作正常,当然内容工作正常以及:
启用蓝牙 - 无需root
adb shell content insert --uri content://settings/global --bind name:s:bluetooth_disabled_profiles --bind value:s:1 --user 0
禁用蓝牙 - 无需root:
adb shell content insert --uri content://settings/global --bind name:s:bluetooth_disabled_profiles --bind value:s:0 --user 0
关于小米米4i / MIUI 9:
启用:
adb shell服务调用bluetooth_manager 8
要禁用:
adb shell服务调用bluetooth_manager 10
这也可以在Android中运行,如:
服务电话bluetooth_manager 10
正如awm129指出的那样,使用service call
的解决方案与设备无关。虽然我无法完全消除service call
的使用,但以下解决方案应该更加独立于设备:
要禁用:
pm disable com.android.bluetooth
启用:
pm enable com.android.bluetooth
service call bluetooth_manager 6
我希望有人最终会找到一个免费的service call
解决方案。