I'm trying to implement my own timeout on my bluetooth GATT services by schedule a timer and call BluetoothGatt.disconnect()
manually. But the callback is not called like what usually happen if the disconnect is triggered from the remote devices. There is also a log from the BluetoothGatt
that the disconnect function is called
D/BluetoothGatt﹕ cancelOpen() - device: 00:07:80:04:1A:5A
and this is my code to disconnect
private void scheduleDisconnect() {
isTimerRunning = true;
disconnectTimer = new Timer();
disconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
isTimerRunning = false;
disconnect();
}
}, 2000);
}
Why is onConnectionStateChange
not called?
It's working well for another callback and action
Is your disconnect() method closing the connection as well? Only call BluetoothGatt.close() when you are done with the device, or else your callbacks will be unregistered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With