gpt4 book ai didi

android - 蓝牙 socket 连接

转载 作者:太空宇宙 更新时间:2023-11-03 10:32:00 26 4
gpt4 key购买 nike

我如何知道 BluetoothSocket 是否仍连接到端点?我如何检测套接字是否已被端点断开连接?

谢谢

最佳答案

在我的应用程序中,我会跟踪 I/O 错误。如果 read() 成功,我就会重置计数器。如果错误计数器上升到足够高(4-5 通常是一个很好的数字),那么我认为连接已死,然后继续将其拆除并重新构建。

SDK 谈到了状态更改 Intent ,但我不清楚它是指特定连接还是蓝牙适配器本身 here :

Optionally, your application can also listen for the ACTION_STATE_CHANGED broadcast Intent, which the system will broadcast whenever the Bluetooth state has changed. This broadcast contains the extra fields EXTRA_STATE and EXTRA_PREVIOUS_STATE, containing the new and old Bluetooth states, respectively. Possible values for these extra fields are STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF, and STATE_OFF. Listening for this broadcast can be useful to detect changes made to the Bluetooth state while your app is running.

关于android - 蓝牙 socket 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3148048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com