Android 蓝牙 - 确定配对设备是否“打开”
我想确定配对的设备当前是否处于活动状态。我真的不需要连接它,只需确定它是否有心跳即可。
我在尝试连接蓝牙套接字时遇到了一系列 IO 错误,但我不确定我是否真的需要这样做。
I want to determine if a paired device is currently active. I don't really need to connect to it, just determine if it has a heartbeat.
I'm fighting a series of IO errors while trying to connect a bluetooth socket, but I'm not sure I really need to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用的是 Android
如果您有该设备的 BluetoothDevice 对象,则可以注册监听广播操作 - ACL_CONNECTED 或 ACL_DISCONNECTED 并跟踪连接状态。
Assuming you are using Android
If you have a BluetoothDevice object to this device, you can register to listen for the Broadcast Actions - ACL_CONNECTED or ACL_DISCONNECTED and keep track of the connection state.
如果您想了解 BT 耳机当前是否已主动连接(音频正在路由到它),请执行以下操作:
声明以下意图过滤器
,并在您的 Receiver 中的 onReceive 检查:
并将 int 保存为静态变量。您可以随时访问它,了解 BT 音频是否已连接 (1) / 已断开连接 (0)。不漂亮,但完成了工作。
另请查看:
https://github.com/android/platform_frameworks_base /blob/gingerbread/core/java/android/bluetooth/BluetoothHeadset.java
If you want to find out wether a BT-Headset is currently actively connected (audio being routed to it), do the following:
Declare the following intent-filter
and in your Receiver in onReceive check for:
and save the int as a static variable. Access it anytime you want to know if BT audio is connected(1) / disconnected(0). Not pretty, but gets the job done.
Also check out:
https://github.com/android/platform_frameworks_base/blob/gingerbread/core/java/android/bluetooth/BluetoothHeadset.java