Bluetooth GATT disconnected onConnectionStateChange not called

I am trying to implement my own timeout in my Bluetooth GATT services on a timer schedule and call BluetoothGatt.disconnect()

manually. But the callback is not called the way it would normally be if disconnect is disabled from remote devices. There is also a log from BluetoothGatt

that the disconnect function is called

D/BluetoothGatt﹕ cancelOpen() - device: 00:07:80:04:1A:5A

      

and this is my code to disable

private void scheduleDisconnect() {
    isTimerRunning = true;
    disconnectTimer = new Timer();
    disconnectTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            isTimerRunning = false;
            disconnect();
        }
    }, 2000);
}

      

Why is onConnectionStateChange

n't it called? It works well for other callback and action.

+3


source to share


2 answers


Is your disconnect () method closing the connection? Only choose BluetoothGatt.close () when you are done with the device, otherwise your callbacks will be unregistered .



+1


source


To disconnect my device, I use the device gatt link and I use the BluetoothGatt.disconnect () and BluetoothGatt.close () methods.



This worked, but did not call onConnectionStateChange () because I am closing the stream.

0


source







All Articles