从ADB或启动时启动蓝牙?

时间:2013-08-28 19:19:00

标签: android bluetooth

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

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

但这需要用户按OK。和

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测试。)

2 个答案:

答案 0 :(得分:4)

在有根设备上

adb shell service call bluetooth_manager 8

适合我。

答案 1 :(得分: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为服务创建并注册intent过滤器,并使用adb命令启动它:

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

如果手机没有植根,似乎没有其他办法可以做到。如果有根,service call bluetooth 3应该有效。

本教程中描述了一个有效的解决方案:How to launch an Android app from adb - And toggle bluetooth。他们使用此应用:Bluetooth On/Off Toggle App.