5

是否可以在无需用户干预的情况下从 ADB 启动蓝牙?我试过了:

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

但这需要用户按确定。和:

service call bluetooth 3

不做任何事情。在 init.rc 中启用蓝牙服务也不起作用。

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

我更喜欢亚行的命令。(如果有人想知道我需要它来进行 FCC 测试。)

4

2 回答 2

4

在有根设备上

adb shell service call bluetooth_manager 8

为我工作。

于 2014-06-10T07:06:24.950 回答
3

如果它适合您,应用程序可以轻松更改蓝牙状态。代码很简单,相信大家都很熟悉:

BluetoothAdapter.getDefaultAdapter().enable()

这可能是一个“无头”应用程序,其服务仅侦听特定意图。您可以安装它,然后广播激活器意图。

如果您希望应用程序不出现在应用程序“抽屉”中(仅在“设置”->“应用程序”中),则从AndroidManifest.xml文件中删除启动器和主要意图过滤器。也就是说,删除这些:

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

从此时起,您可以使用您在清单文件中为其定义的意图启动应用程序/服务。例如,您可以使用操作为服务创建和注册意图过滤器,com.company.service.bluetooth.ON并使用 adb 命令启动它:

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

如果手机没有root,似乎没有其他方法可以做到这一点。如果扎根,service call bluetooth 3应该可以工作。

本教程中描述了一个可行的解决方案:如何从 adb 启动 Android 应用程序 - 并切换蓝牙。他们使用这个应用程序:蓝牙开/关切换应用程序。

于 2013-08-28T19:40:25.270 回答