use*_*518 6 shell terminal command bluetooth adb
我正在尝试使用命令行在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 **
但它不会与设备无关.
Rav*_*jan 15
启用:
adb shell service call bluetooth_manager 6
Run Code Online (Sandbox Code Playgroud)
要禁用:
adb shell service call bluetooth_manager 8
Run Code Online (Sandbox Code Playgroud)
小智 12
启用
svc bluetooth enable
Run Code Online (Sandbox Code Playgroud)
禁用
svc bluetooth disable
Run Code Online (Sandbox Code Playgroud)
对于蓝牙状态:
adb shell settings get global bluetooth_on
Run Code Online (Sandbox Code Playgroud)
要么
adb shell settings list global |grep ^bluetooth_on
Run Code Online (Sandbox Code Playgroud)
启用蓝牙
adb shell settings put global bluetooth_on 1
Run Code Online (Sandbox Code Playgroud)
禁用蓝牙
adb shell settings put global bluetooth_on 0
Run Code Online (Sandbox Code Playgroud)
通过am-代替请求,使用enable
adb shell am broadcast -a android.intent.action.BLUETOOTH_ENABLE --ez state true
Run Code Online (Sandbox Code Playgroud)
通过关键事件
adb shell am start -a android.settings.BLUETOOTH_SETTINGS
adb shell input keyevent 19
adb shell input keyevent 23
Run Code Online (Sandbox Code Playgroud)
最终想出了一种在没有根目录的情况下在Android 8.0和更高版本上打开/关闭蓝牙的方法,“ bluetooth_on”似乎不再适用于最新的android版本:
启用蓝牙-无需root
adb shell settings put global bluetooth_disabled_profiles 1
Run Code Online (Sandbox Code Playgroud)
禁用蓝牙-无需root
adb shell settings put global bluetooth_disabled_profiles 0
Run Code Online (Sandbox Code Playgroud)
由于上述工作正常,所以内容当然也可以工作:
启用蓝牙-无需root
adb shell content insert --uri content://settings/global --bind name:s:bluetooth_disabled_profiles --bind value:s:1 --user 0
Run Code Online (Sandbox Code Playgroud)
禁用蓝牙-无需root:
adb shell content insert --uri content://settings/global --bind name:s:bluetooth_disabled_profiles --bind value:s:0 --user 0
Run Code Online (Sandbox Code Playgroud)
小智 5
对于那些想知道数字 6 和 8 从何而来的人来说。它来自这个aidl文件:https://android.googlesource.com/platform/system/bt/+/master/binder/android/bluetooth/IBluetoothManager.aidl 从这个aidl中列出的第一个函数开始计数,你会看到启用功能是列表中的第 6 个功能,禁用功能是第 8 个功能。
小智 5
这可能是一个有点hacky的解决方案,但是一旦您尝试启用或禁用蓝牙,您可以使用右键操作,然后使用回车键操作来选择通常位于最右侧的允许按钮。
即使您的设备没有root,这也应该可以工作。
启用:
adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
adb shell input keyevent 22 (right)
adb shell input keyevent 22 (right)
adb shell input keyevent 66 (enter)
Run Code Online (Sandbox Code Playgroud)
禁用:
adb shell am start -a android.bluetooth.adapter.action.REQUEST_DISABLE
adb shell input keyevent 22 (right)
adb shell input keyevent 22 (right)
adb shell input keyevent 66 (enter)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24522 次 |
| 最近记录: |