蓝牙插座连接

发布于 2024-09-07 10:26:34 字数 66 浏览 3 评论 0原文

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

谢谢

How can i know if a BluetoothSocket is still connected to the endpoint? How can i detect if the socket has been disconnected by the endpoint?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-09-14 10:26:34

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

SDK谈论了状态改变意图,但我不清楚它是指特定连接,还是蓝牙适配器本身此处

您的应用程序还可以选择
监听 ACTION_STATE_CHANGED
广播Intent,系统
每当蓝牙连接时就会广播
状态已经改变。本次广播
包含额外字段 EXTRA_STATE
和 EXTRA_PREVIOUS_STATE,包含
新旧蓝牙状态,
分别。可能的值
这些额外的字段是
STATE_TURNING_ON、STATE_ON、
STATE_TURNING_OFF 和 STATE_OFF。
收听此广播可以
有助于检测对
您的应用程序运行时的蓝牙状态
正在运行。

In my apps, I keep track of I/O errors. If a successful read() takes place, then I reset the counters. If the error counters go up high enough (4-5 is usually a good number) then I consider the connection dead, and proceed to tear it down and re-build it.

The SDK talks about a state change intent, but I'm not clear whether it's referring to a specific connection, or the bluetooth adapter itself 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文