Reputation: 11112
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
Upvotes: 6
Views: 9272
Reputation: 268
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.
Upvotes: 2
Reputation: 36
To disconnect my device, I use the gatt link of the device and I use the methods BluetoothGatt.disconnect() and BluetoothGatt.close().
This worked, but didn't call onConnectionStateChange(), because I close the flux.
Upvotes: 0