Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth GATT disconnect onConnectionStateChange not called

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

like image 767
Niko Adrianus Yuwono Avatar asked Jan 07 '15 05:01

Niko Adrianus Yuwono


1 Answers

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.

like image 86
Ron Avatar answered Oct 15 '22 08:10

Ron