Android - 蓝牙设备连接广播
我想要一个广播接收器来监听 BT 设备的连接。 谁能告诉我该听哪个广播? 我尝试了 android.bluetooth.device.action.ACL_CONNECTED 但它似乎不起作用。
谢谢。
I want to have a broadcast receiver listening for BT devices connecting.
Could anybody tell me which broadcast I have to listen to?
I tried android.bluetooth.device.action.ACL_CONNECTED
but it doesn't seem to work.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在查看设备是否正在“连接”,那么您需要 android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED
但是,当设备处于 STATE_CONNECTED 状态时,不会触发此操作。所以我所做的是当状态正在连接时,在几秒钟内发送广播。
有点 hackish,这就是我在 Android 缺陷跟踪器中发布此问题的原因。 http://code.google.com/p/android/issues/detail ?id=25957
If you are looking whether the device is "connecting" then you'd want android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED
However, this does not get triggered when the device is STATE_CONNECTED. So what I did was when the state is connecting, to send a broadcast in a few seconds.
Kind of hackish, which is why I posted this issue in the Android defect tracker. http://code.google.com/p/android/issues/detail?id=25957
您可以在
BroadcastReceiver.onReceive()
函数中使用以下代码来拉取设备:You can pull the device by using the following inside your
BroadcastReceiver.onReceive()
function: