Start Bluetooth from ADB or startup?

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.)

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:

    
    

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.

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Start Bluetooth from ADB or startup?

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录