24

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.

user2661518
  • 2,677
  • 9
  • 42
  • 79

10 Answers10

24

Updated: 2023-03-10 - Android 12/13

Enable bluetooth via cmd

adb shell cmd bluetooth_manager enable

Disable bluetooth cmd

adb shell cmd bluetooth_manager disable

Updated: 2019-06-22: - Android 11

Print current bluetooth status via settings

adb shell settings get global bluetooth_on 
adb shell settings list global |grep ^bluetooth_on

Enable Bluetooth via settings

adb shell settings put global bluetooth_disabled_profiles 1 

Disable bluetooth settings

adb shell settings put global bluetooth_disabled_profiles 0

Enable bluetooth via content

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

Disable bluetooth content

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

Android 11/12/13 and older versions

Enable Bluetooth

adb shell settings put global bluetooth_on 1

Disable Bluetooth

adb shell settings put global bluetooth_on 0

Enable bluetooth via activity manager

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

Disable bluetooth via activity manager

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

Enable/Disable bluetooth via keyevents

adb shell am start \
  -a android.settings.BLUETOOTH_SETTINGS  \
  adb shell input keyevent 19
  adb shell input keyevent 23
wuseman
  • 1,259
  • 12
  • 20
  • 1
    On Huawei P30 Pro with Android P even your new solution doesn't work. When I use `adb shell settings put global bluetooth_disabled_profiles 1`, it **disables** bluetooth (as opposite to what you say) and `adb shell settings put global bluetooth_disabled_profiles 0` does nothing, it doesn't enable nor disable it. – Robyer Jul 11 '19 at 12:42
  • 1
    See if they have changed the name so it might be bluetooth_on instead of bluetooth_disabled_profiles. If you type 'adb shell settings list global|grep -i bluetooth' you should get some alternatives what you can try if above dosn't work so just change name and value if needed, above works fine on Huawei P9, Samsung S8 and Huawei P8 that's all I have tried on with Android 8.0 & Android 9.0. Regards – wuseman Jul 12 '19 at 11:05
  • For reference, `adb shell settings put global bluetooth_on 1` worked on a Samsung S7 – TripeHound Mar 27 '20 at 11:28
  • 1
    for me, all of these methods from 2019 edit (both disable and enable) disable bluetooth for just a very quick amount of time. It rather looks like a reset. Samsung A50, Android 10 (kernel 4.14 ) – Antek Mar 22 '21 at 09:40
  • `adb shell settings put global bluetooth_on 0` worked for me in android 12.1 - but is there anyway that I can make it non-persistent so that behavior is same after each boot? When `settings put global bluetooth_on 0` - it retains the value and next time I reboot, I notice that boot_completed never gets set to 1. Unless I wipe /data partition and restart again and re-put `settings put global bluetooth_on 0`. – mohdyusuf May 23 '23 at 21:15
18

To enable:

adb shell service call bluetooth_manager 6

To disable:

adb shell service call bluetooth_manager 8
Alex P.
  • 30,437
  • 17
  • 118
  • 169
Ravi Ranjan
  • 399
  • 1
  • 5
  • 11
  • Both commands did not work for me. I am using Samsung S4 device and its Android 4.2. – Codelearner Jul 11 '17 at 23:04
  • We are trying to enable and disable Bluetooth before we start our automation test using adb commands Enable adb shell service call bluetooth_manager 6 Disable adb shell service call bluetooth_manager 9 We are getting the Bluetooth status using this command adb shell settings get global bluetooth_on Are there any other work around to enable and disable the bluetooth using APPIUM java because these commands working in some devices but not in all the device. Any solution for this? The same commands working in Android 5 (Lollipop) – alk1985 Feb 14 '18 at 09:34
  • 2
    using static method codes as suggested here will never work across all devices. These codes can and do change on a per device basis depending on vendor and OEM modifications. – awm129 Oct 23 '18 at 17:08
  • Is there a document specifying what 6 and 8 state means? – AIB Dec 10 '18 at 10:34
  • this worked for Moto E4 on Android v7.1.1 - but only with root: `adb shell su -c "service call bluetooth_manager 8"` – Eugen Oct 07 '21 at 19:34
12

To enable

svc bluetooth enable

To disable

svc bluetooth disable
Hari Nandha
  • 254
  • 2
  • 5
5

This might be a bit of a hacky solution but once you try to enable or disable bluetooth, you can use the right key action followed by the enter key action to select the allow button which is usually on the very right.

This should work even if your device is not rooted.

To enable:

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)

To disable:

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)
Safa
  • 51
  • 1
  • 1
4

For folks who are wondering from where did the numbers 6 and 8 came from. It came from this aidl file: https://android.googlesource.com/platform/system/bt/+/master/binder/android/bluetooth/IBluetoothManager.aidl Start counting from the first function listed in this aidl and you will see the enable function is the 6th one and the disable is the 8th one in the list.

VinPat
  • 41
  • 3
3

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

  • When I run this command I get a strange output (similar to what xxd produces) that has the message `Attempt to invoke virtual method 'java.lang.String android.content.AttributionSource.getPackageName(' on a ull object reference.d,..at com.android.server.BluetoothManagerService.enableNoAutoConnect(BluetoothManagerService.java:1136)..at android.bluetooth.IBluetoothManager$Stub.onTransact(IBluetoothManager.java:294)..at ndroid.os.Binder.execTransactInterval(Binder.java:1184)..at android.os.Binder.execTransact(Binder.java:1143)...` – Matthew Apr 05 '23 at 21:43
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.

Aiden
  • 31
  • 3
2

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.

Alex Vong
  • 483
  • 4
  • 15
1

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

Seff
  • 1,546
  • 1
  • 17
  • 19
1

The best way to use settings put, svc, and actions.

It works for all Android versions and all devices.

val isOn =true

val command = "adb shell settings put global bluetooth_on ${
    if (isOn) {
        "1"
    } else {
        "0"
    }
} && adb shell svc bluetooth ${
    if (isOn) {
        "enable"
    } else {
        "disable"
    }
} && adb shell am start -a android.bluetooth.adapter.action.${
    if (isOn) {
        "REQUEST_ENABLE"
    } else {
        "REQUEST_DISABLE"
    }
} && adb shell am broadcast -a android.intent.action.BLUETOOTH_ENABLE --ez state $isOn"
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78