I have a application for controlling multiple Bluetooth LE lamps.
When I want to disconnect all devices at same time, I call BluetoothGatt disconnect, and close from onConnectionStateChange, getConnectionState will return STATE_DISCONNECTED, but sometimes some devices' connection is still alive.
I can see the closed logs.
BluetoothGatt: close()
unregisterApp() - mClientIf=xx
But I can't see the disconnected log.
onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth disconnect broadast for xxx
I used ReentrantLock to make sure every device only has one Gatt, and executing control functions on main thread by MainThread annotation, but the issue still exists.
How can I fix this issue?
Finally, I solved this problem. The reason is that I can't connect multiple devices at the same time. So I used a queue to connect the devices one by one.