Android - Can I Restart Bluetooth From The Terminal?


Answer :

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.


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 

Enable bluetooth:
service call bluetooth 3

Disable bluetooth:
service call bluetooth 4


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable