Reputation: 256
I am trying to read data from a BLE device 24/7. I am able to scan it and can get the data but when the device is not in the range, then it will scan every 30 seconds ( I have created a handler) and after 32 attempts the app will crash. I checked the log and I am getting the following error
can't register GATT client, Max client reached: 32
Register with GATT stack failed.
This is my code that that runs when the BLE device is disconnected
if(newstate = BluetoothProfile.STATE_DISCONNECTED) {
if(mGatt !=null) {
mGatt.close();
mGatt = null;
}
queues.clear();
handler.postDelayed(runnable = new Runnable(){
public void run(){
handler.postDelayed(runnable, delay) //3000ms delay
BLEManager.getInstance().connectDevice(address) // device trying to reconnect
}
}, delay);
}
Any suggestions will be highly appreciated
Upvotes: 1
Views: 433
Reputation: 355
First of all,
I'd suggest you to use RxAndroidBle or Kable for cleaner code.
Each device has a Gatt connection limit. To not reach that limit you have to close connection when you done with that Gatt object.
Upvotes: 2