Start Bluetooth from ADB or at boot?

android, bluetooth

Solution

If it works for you, an app can easily change the bluetooth state. The code is very simple, I'm sure you're familiar with it:

BluetoothAdapter.getDefaultAdapter().enable()

This could be a "headless" application with a service only that listens for a specific intent. You could install it and then broadcast the activator intent.

If you want the application to not appear in the app "drawer" (only in the Settings->Apps) then remove the launcher and main intent filters from the `AndroidManifest.xml` file. That is, delete these:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

From this time on you can start the app/service with the intent you define for it in the manifest file. For example, you can create and register an intent filter for the service with the action `com.company.service.bluetooth.ON` and start it with the adb command:

am startservice -a com.company.service.bluetooth.ON

There doesn't seem to be any other way to do it if the phone is not rooted. If rooted, the `service call bluetooth 3` should work.

A working solution is described in this tutorial: How to launch an Android app from adb - And toggle bluetooth. They use this app: Bluetooth On/Off Toggle App.

Problem

Is it possible to start Bluetooth from ADB without user intervention? I tried: ``` am start -a android.bluetooth.adapter.action.REQUEST_ENABLE ``` but this require the user to press ok. And: ``` service call bluetooth 3 ``` doesn't do anything. Enabling the bluetoothd service in init.rc doesn't work either. ``` service bluetoothd /system/bin/bluetoothd -n class main socket bluetooth stream 660 bluetooth bluetooth socket dbus_bluetooth stream 660 bluetooth bluetooth # init.rc does not yet support applying capabilities, so run as root and # let bluetoothd drop uid to bluetooth with the right linux capabilities group bluetooth net_bt_admin misc enabled ``` And I would prefer a command from ADB. (If anyone is wondering I need it for FCC testing.)

Original source