android enable disable bluetooth via command line

2019-01-18 16:03发布

问题:

I am trying to enable disable bluetooth on android device using command line.

I can enable it using

adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE

But it prompts user to 'allow' or 'deny'.

I also see there is option to launch ble settings first like

adb shell am start -a android.settings.BLUETOOTH_SETTINGS

and then enable disable adb shell input keyevent **

But it won't be device independent.

回答1:

To enable:

adb shell service call bluetooth_manager 6

To disable:

adb shell service call bluetooth_manager 8


回答2:

To run commands listed in previous comment, you need to be root:

adb root

Enable:

adb shell service call bluetooth_manager 6

Disable:

adb shell service call bluetooth_manager 8



回答3:

To enable:

adb shell service call bluetooth_manager 6

To disable:

adb shell service call bluetooth_manager 9

Tested and worked on a Samsung Galaxy S7.



回答4:

On Xiaomi Mi 4i / MIUI 9:

To enable:

adb shell service call bluetooth_manager 8

To disable:

adb shell service call bluetooth_manager 10

This can also run within Andorid like:

service call bluetooth_manager 10