Android BLE ACL_DISCONNECTED有时会延迟 [英] Android BLE ACL_DISCONNECTED sometimes delayed

查看:170
本文介绍了Android BLE ACL_DISCONNECTED有时会延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序(API 23+),该应用程序通过BLE与设备进行通信.没有配对/绑定.

I am developing an Android app (API 23+) that communicates via BLE with a device. There is no pairing / bonding involved.

交互的快乐路径是,应用程序连接然后向设备发送消息,设备依次发送回信,然后它们都断开连接.

The happy path of the interaction is that the app connects then sends a message to the device, and the device in turn sends a reply back, then they both disconnect.

我在 Android BLE中询问了异常行为的特征意外地从PBAP/MAP蓝牙配置文件重新连接,我创建了一个简单的服务来监视低级蓝牙连接;它会监听BluetoothDevice.ACTION_ACL_CONNECTED和BluetoothDevice.ACTION_ACL_DISCONNECTED的广播.

While characterizing strange behavior I asked in Android BLE unexpectedly reconnects potentially from PBAP / MAP Bluetooth profiles, I created a simple service to monitor low-level bluetooth connections; it listens for broadcasts of BluetoothDevice.ACTION_ACL_CONNECTED and BluetoothDevice.ACTION_ACL_DISCONNECTED.

虽然在大多数情况下,应用程序和设备之间的连接/断开连接很好,但有时应用程序会收到断开连接通知,该通知可能在应用程序和设备都关闭连接后约5-20秒.我已验证设备实际上已关闭,并且应用程序日志全部显示系统正确关闭了连接.

While most of the time the connect / disconnect corresponds well between app and device, sometimes the app receives a disconnect notification that can be ~5-20 seconds after both the app and device have closed the connection. I have verified that the device actually closed, and the app logs all show the system properly shutting down the connection.

在这些情况下,如果该应用在广播ACL_DISCONNECTED之前尝试再次与该设备连接,它将接收到错误,或者随后的连接请求排队,并在广播ACL_DISCONNECTED之后启动.

In these instances, if the app tries to connect again with the device before ACL_DISCONNECTED is broadcast, it will either receive an error or the subsequent connect request is queued and kicked off after the ACL_DISCONNECTED broadcast.

这似乎并不是特定于设备的-我测试了各种品牌和型号-也没有API版本(23-25).

This does not seem to be specific to devices --- I test with a variety of makes and models --- nor the API version (23-25).

  • 这是已知的(预期的)行为吗?
  • 是否有缓解此问题的方法?...以确保确实确实及时地断开了连接?
  • 与接收与ACL相关的广播相反,是否还有更直接的方法(例如,通过API调用)来判断连接是否仍处于正常状态?

推荐答案

如果BLE设备停止广播而不是发送断开信号,则会发生此问题.如果BLE设备未发送断开信号,则Android设备认为连接已打开,并等待一段时间(5-20​​秒),然后使用超时状态代码调用onconnectionstatechange().如果可以使BLE设备发送断开信号而不是停止广播,则它应该可以解决问题.希望这会有所帮助

If the BLE devices stops broadcasting instead of sending disconnect signal this issue happens. If the BLE device didn't send the disconnect signal Android device thinks the that the connection is open and it waits for sometime (5-20 sec) and then calls onconnectionstatechange() with time out status code. If you can make the BLE device send the disconnect signal instead of stop broadcasting it should fix the issues. Hope this helps

这篇关于Android BLE ACL_DISCONNECTED有时会延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆