微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android 蓝牙 Gatt 服务器/客户端断开连接问题

如何解决Android 蓝牙 Gatt 服务器/客户端断开连接问题

问题:Android 客户端/服务器通过 BLE Gatt 连接,一个设备与另一个设备断开连接,然后断开连接的回调要么超时,据我所知是由制造商完成的,要么花费太长时间,要么永远不会叫!

我相信我遇到的问题是以下方法从未被调用。正如你所看到的,第一个设备调用了这些方法,但连接状态从未改变,所以只有下面的方法调用,回调从未出现。但方法已更新。

2021-04-22 08:53:00.771 14607-14982/app D/BluetoothGatt: onConnectionUpdated() - Device=60:9B:02:00:D7:97 interval=36 latency=0 timeout=500 status=0
2021-04-22 08:53:01.294 14607-14982/app D/BluetoothGattServer: onServerConnectionState() - status=0 serverIf=12 device=6C:C2:12:08:74:27

这里从未调用onConnectionStateChange 并且该方法在 ServerGatt 上完全可用:

/**
     * Callback indicating the connection parameters were updated.
     *
     * @param device The remote device involved
     * @param interval Connection interval used on this connection,1.25ms unit. Valid range is from
     * 6 (7.5ms) to 3200 (4000ms).
     * @param latency Slave latency for the connection in number of connection events. Valid range
     * is from 0 to 499
     * @param timeout Supervision timeout for this connection,in 10ms unit. Valid range is from 10
     * (0.1s) to 3200 (32s)
     * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
     * successfully
     * @hide
     */
    public void onConnectionUpdated(BluetoothDevice device,int interval,int latency,int timeout,int status) {
    }

这里是客户端的 onConnectionStateChange 和 GattClient 可用但从未调用过的方法

/**
     * Callback indicating the connection parameters were updated.
     *
     * @param gatt GATT client involved
     * @param interval Connection interval used on this connection,in 10ms unit. Valid range is from 10
     * (0.1s) to 3200 (32s)
     * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
     * successfully
     * @hide
     */
    public void onConnectionUpdated(BluetoothGatt gatt,int status) {
    }

这些方法也是公开的,但无法覆盖它们,我真的不明白为什么我认为 Android 本身可能存在错误。任何反馈将不胜感激。

有人遇到过这种问题吗?

如果需要,我可以为两个设备提交错误报告。

谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。