Hi want implement Ble retry ,if it is more than 3 times attempts every 5 sec delay.
Below code not working it is calling only once.
else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
// disconnected from the GATT Server
if(connectionRetries < 3) {
Log.d("data uri","mRetries"+mRetries);
connectionRetries ++;
try {
connectToBleGattServer(bleDevice,activity);
Thread.sleep(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Connectgattserver method:
public boolean connectToBleGattServer(BluetoothDevice bleDevice, Activity context) {
if (bleDevice == null || bluetoothGattCallback == null) return false;
try {
if (Build.VERSION.SDK_INT >= 23) {
Log.d("PesBleDevice", "New method of connection is called with transport value of 2..");
bluetoothGatt = bleDevice.connectGatt(context, false, bluetoothGattCallback, 2);
connectionStateChangeListenerQueue.add(new ENHOBleCallback());
Log.d("PesBleDevice", "Ble Connected");
} else {
bluetoothGatt = bleDevice.connectGatt(context, false, bluetoothGattCallback);
connectionStateChangeListenerQueue.add(new ENHOBleCallback());
Log.d("PesBleDevice", "New method of connection is called...");
}
return true;
} catch (Exception e) {
Log.d("PesBleDevice", "Unable to connect.");
return false;
}
}