I have a ready-to-send application that connects to the custom Bluetooth peripheral we made. However, I just found a problem with an application that I cannot install.
I do all my Bluetooth operations in Service , and sometimes when I need the bluetooth operations to end, I end up with 1 peripheral device still connected, but I lost all the pointers to it. From time to time, the entire bluetooth stack is blocked and requires a phone reboot.
I think that problems arise when I try to clean up any connected devices after I stopped scanning. I have this cleaning method
private void clearAllDevices() { Log.e(TAG, "Clear all devices"); for (int i = 0; i < _connectedPeripherals.size(); i++) { Log.e(TAG, "int i:" + i + " _connectedPeripherals size:" + _connectedPeripherals.size()); BluetoothGatt gatt = (BluetoothGatt) _connectedPeripherals.get(i); gatt.disconnect(); } }
However, sometimes I think that the peripheral device is halfway through the connection at the same time as disconnecting from everything that has the connection.
Is there a better way to clear all connected devices or devices that are in the process of connecting?
source share