Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android enable disable bluetooth via command line

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.

like image 392
user2661518 Avatar asked May 16 '16 16:05

user2661518


People also ask

How do I turn off Bluetooth on my Android phone?

It's also easy to disable Bluetooth from the Settings app, but it takes a few more taps. To do it, open Settings and navigate to Connected Devices > Connection Preferences > Bluetooth and turn off the switch beside “Use Bluetooth.”

How do I enable Bluetooth disabled by administrator?

Method 1: Disable or Enable Bluetooth in Bluetooth SettingsPress the Windows key + I together to open the Settings app. Navigate to Devices -> Bluetooth & other devices. On the right side, you can use the “Bluetooth” option to disable or enable Bluetooth.


2 Answers

To enable:

adb shell service call bluetooth_manager 6

To disable:

adb shell service call bluetooth_manager 8
like image 133
Ravi Ranjan Avatar answered Sep 21 '22 05:09

Ravi Ranjan


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 
like image 23
wuseman Avatar answered Sep 21 '22 05:09

wuseman