8

I have a rooted Galaxy S 2 (I9100) and was wondering if I can restart the Bluetooth on my phone via the terminal client on my phone.

10

The following terminal command should enable Bluetooth via adb shell or Terminal Emulator app:

su
am start -a android.bluetooth.adapter.action.REQUEST_ENABLE

On most versions of Android, this command will present a pop-up window to the user asking to confirm request to enable BT. I believe this was done for security purposes whenever an app that is not system is toggling BT.

I haven't found a way to disable BT via a shell command unfortunately.

With WiFi it's a lot easier, and does not prompt user for permission:

su
svc wifi enable

will turn it on, and

su
svc wifi disable

will turn it off.

  • Thanks for the answer. I'll try the same. Could you also list the same for WiFi? – Clyde Lobo Apr 5 '12 at 9:43
  • Edited my answer with the WiFi info. I haven't found a way to disable BT via a terminal command though :( – Chahk Apr 5 '12 at 12:42
6

in android.bluetooth.IBluetoothManager, there some parameters

TRANSACTION_registerAdapter = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); TRANSACTION_unregisterAdapter = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1); TRANSACTION_registerStateChangeCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2); TRANSACTION_unregisterStateChangeCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3); TRANSACTION_isEnabled = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4); TRANSACTION_enable = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5); TRANSACTION_enableNoAutoConnect = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6); TRANSACTION_disable = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
TRANSACTION_getAddress = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8); TRANSACTION_getName = (android.os.IBinder.FIRST_CALL_TRANSACTION + 9);

android.os.IBinder.FIRST_CALL_TRANSACTION=1

SO, with rooted device, if you want to turn off bluetooth in adb shell super user mode (su)

service call bluetooth_manager 8

if you want to turn on bluetooth again

service call bluetooth_manager 6
  • device I use is HTC One with android 4.4.2 – Jamy Apr 17 '14 at 3:54
  • Confirm, that this is working on Android 4.2.2 – pevik Feb 4 '15 at 11:29
  • Service bluetooth_manager does not exist on Android 4.1.2 – davide Aug 16 '15 at 10:30
3

Enable bluetooth:
service call bluetooth 3

Disable bluetooth:
service call bluetooth 4

  • Negative voter: could you help identifying the issue with this answer (after edit)? These worked in my rooted phone after su - so technically nothing wrong AFAIK. – Narayanan Aug 2 '13 at 11:38
  • 1
    Enable bluetooth: service call bluetooth 3 Disable bluetooth: service call bluetooth 5 is working on my HTC Desire X – Anvesh Yalamarthy Aug 25 '14 at 11:53
  • 1
    service call bluetooth 5 works in my Android 4.2.1 to disable bluetooth. – Firelord Jul 2 '15 at 17:53
  • On a "Galaxy Fame GT-6810P", the correct numbers are 3 and 5. – davide Aug 16 '15 at 10:32
1

This works from a shell:

am start -a android.bluetooth.adapter.action.REQUEST_ENABLE & input keyevent 20 & adb shell input keyevent 21 & adb shell input keyevent 23

Basically it causes the dialogue to appear and then sends keystrokes to accept the command

0

My solution works.

am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
sleep 1
input tap 872 1072

Notice that when execute first command, it jumps out a window ask you to select ALLOW.

So you need the auto click command.

You can get the X,Y position by enable Developer options->Pointer location, then touch the ALLOW button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.