【发布时间】:2011-11-04 08:08:19
【问题描述】:
我想在连接特定蓝牙设备时启动服务,并在断开连接时停止该服务。 显然我不想让后台服务一直检查是否连接了 BT 设备,所以我想用 Receiver 来实现。
这真的可能吗? android.bluetooth.device.action.ACL_CONNECTED 提到了here,但显然它不起作用。
谢谢!
【问题讨论】:
标签: android bluetooth broadcastreceiver
我想在连接特定蓝牙设备时启动服务,并在断开连接时停止该服务。 显然我不想让后台服务一直检查是否连接了 BT 设备,所以我想用 Receiver 来实现。
这真的可能吗? android.bluetooth.device.action.ACL_CONNECTED 提到了here,但显然它不起作用。
谢谢!
【问题讨论】:
标签: android bluetooth broadcastreceiver
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
这些是您必须使用广播接收器添加的过滤器。
ACL_CONNECTED 表示蓝牙连接,ACL_DISCONNECTED 表示蓝牙断开
对于特定设备,您必须检查广播接收器中的意图/上下文
您必须添加的两个权限是:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
我认为这应该可以解决您的问题。
【讨论】: