android enable disable bluetooth via command line

后端 未结 10 2033
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 16:21

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.ac

相关标签:
10条回答
  • 2020-12-05 16:43

    As awm129 has pointed out, solutions using service call aren't device-independent. While I am unable to completely eliminate the use of service call, the following solution should be more device-independent:

    To disable:

    pm disable com.android.bluetooth
    

    To enable:

    pm enable com.android.bluetooth
    service call bluetooth_manager 6
    

    I hope someone will eventually find a service call-free solution.

    0 讨论(0)
  • 2020-12-05 16:45

    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

    0 讨论(0)
  • 2020-12-05 16:47

    To enable:

    adb shell service call bluetooth_manager 6
    

    To disable:

    adb shell service call bluetooth_manager 8
    
    0 讨论(0)
  • 2020-12-05 16:50

    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

    0 讨论(0)
  • 2020-12-05 16:56

    I do not have enough reputation points to add a comment so I am following up on TripeHound's comment on wuseman's answer.

    I tried TripeHound's way of setting the Bluetooth global setting (

    adb shell settings put global bluetooth_on 1
    

    ) on a Samsung Galaxy Tab A (SAMSUNG SM-T515 running Android 10, Kernel 4.4.177) and it does indeed seem to work. However, the Bluetooth icon will not show the change when opening the quick-settings menu nor will it show the change when you go to the full settings menu.

    That said, if I restart the tablet immediately after it will indeed reboot with the correct state so I am not sure whether it is necessary to re-read the global settings somehow to ensure that the Bluetooth radio is actually off.

    Comments appreciated!

    0 讨论(0)
  • 2020-12-05 16:57

    For bluetooth status:

    adb shell settings get global bluetooth_on 
    

    or

    adb shell settings list global |grep ^bluetooth_on
    

    Enable Bluetooth

    adb shell settings put global bluetooth_on 1
    

    Disable Bluetooth

    adb shell settings put global bluetooth_on 0
    

    Via am - Instead of request, use enable

    adb shell am broadcast -a android.intent.action.BLUETOOTH_ENABLE --ez state true
    

    Via Keyevents

    adb shell am start -a android.settings.BLUETOOTH_SETTINGS 
    adb shell input keyevent 19
    adb shell input keyevent 23
    

    Edit 2019-06-22:

    Finally figured out a way to toggle bluetooth on/off on Android 8.0 and newer versions without root, "bluetooth_on" doesn't seems to work on latest android versions anymore:

    Enable Bluetooth - No root required

      adb shell settings put global bluetooth_disabled_profiles 1 
    

    Disable Bluetooth - No root required

      adb shell settings put global bluetooth_disabled_profiles 0
    

    And since above works fine then of course content works fine aswell:

    Enable Bluetooth - No root required

     adb shell content insert --uri content://settings/global --bind name:s:bluetooth_disabled_profiles --bind value:s:1 --user 0 
    

    Disable Bluetooth - No root required:

     adb shell content insert --uri content://settings/global --bind name:s:bluetooth_disabled_profiles --bind value:s:0 --user 0 
    
    0 讨论(0)
提交回复
热议问题