Java BLE断开并关闭Gatt,getConnectionState处于连接状态,但设备连接仍处于活动状态
我有一个控制多个蓝牙LED灯的应用程序 当我想同时断开所有设备的连接时,我调用BluetoothGatt disconnect,并从onConnectionStateChange关闭,getConnectionState将返回状态\u DISCONNECTED,但有时某些设备的连接仍然处于活动状态 我可以看到关闭的日志Java BLE断开并关闭Gatt,getConnectionState处于连接状态,但设备连接仍处于活动状态,java,android,bluetooth-lowenergy,android-bluetooth,bluetooth-gatt,Java,Android,Bluetooth Lowenergy,Android Bluetooth,Bluetooth Gatt,我有一个控制多个蓝牙LED灯的应用程序 当我想同时断开所有设备的连接时,我调用BluetoothGatt disconnect,并从onConnectionStateChange关闭,getConnectionState将返回状态\u DISCONNECTED,但有时某些设备的连接仍然处于活动状态 我可以看到关闭的日志 BluetoothGatt: close() unregisterApp() - mClientIf=xx 但我看不到断开连接的日志 onReceive: android.b
BluetoothGatt: close()
unregisterApp() - mClientIf=xx
但我看不到断开连接的日志
onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth disconnect broadast for xxx
我使用ReentrantLock确保每个设备只有一个Gatt,并通过MainThread注释在主线程上执行控制函数,但问题仍然存在
如何解决此问题
最后,我解决了这个问题。 原因是我不能同时连接多个设备。
因此,我使用队列逐个连接设备 我有时也会看到同样的事情,顺便说一句,这里有一个讨论。谢谢,但这个问题与那个问题不同。在我断开设备连接后,我可以再次发现,BluetoothManager告诉我设备已断开连接,但设备连接仍处于活动状态,我没有收到断开连接的广播消息。我有时会看到同样的情况,这里是一个讨论btw。谢谢,但这个问题与那个问题不同。断开设备连接后,我可以再次发现,BluetoothManager告诉我设备已断开连接,但设备仍处于连接状态,我没有收到断开连接的广播消息。