简体   繁体   English

蓝牙GATT断开onConnectionStateChange不被调用

[英]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. 我正在尝试通过安排计时器并手动调用BluetoothGatt.disconnect()在我的蓝牙GATT服务上实现自己的超时。 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 还有来自BluetoothGatt的日志,称为断开连接功能

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? 为什么不调用onConnectionStateChange It's working well for another callback and action 对于另一个回调和操作,它运行良好

Is your disconnect() method closing the connection as well? 您的Disconnect()方法是否也会关闭连接? Only call BluetoothGatt.close() when you are done with the device, or else your callbacks will be unregistered . 仅在使用完设备后才调用BluetoothGatt.close(),否则您的回调将被取消注册

To disconnect my device, I use the gatt link of the device and I use the methods BluetoothGatt.disconnect() and BluetoothGatt.close(). 要断开设备连接,请使用设备的gatt链接,并使用BluetoothGatt.disconnect()和BluetoothGatt.close()方法。

This worked, but didn't call onConnectionStateChange(), because I close the flux. 这可行,但没有调用onConnectionStateChange(),因为我关闭了助焊剂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM