Flutter blue 蓝牙扫描连接不稳定问题

本文探讨了使用 Flutter Blue 在 Android 平台上遇到的蓝牙设备扫描和连接不稳定的问题,主要与 gatt close bug 相关。在 `FlutterBluePlugin` 类的 `disconnect` 情况下,当尝试断开连接时,状态更新的延迟导致 `close` 方法可能无法正确执行。此外,`onConnectionStateChange` 方法中对断开连接状态的处理也存在优化空间。解决方案可能涉及调整蓝牙设备状态检查和关闭的时机。
摘要由CSDN通过智能技术生成

@[Flutter Blue] @[Android]

Flutter blue Android 蓝牙扫描连接不稳定问题

主要和gatt close bug 有关

https://github.com/pauldemarco/flutter_blue/blob/master/android/src/main/java/com/pauldemarco/flutter_blue/FlutterBluePlugin.java

line: 318
case “disconnect”:
{
String deviceId = (String)call.arguments;
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(deviceId);
int state = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
BluetoothDeviceCache cache = mDevices.remove(deviceId);
BluetoothDeviceCache cache = mDevices.get(deviceId);
if(cache != null) {
BluetoothGatt gattServer = cache.gatt;
gattServer.disconnect();
if(state == BluetoothProfile.STATE_DISCONNECTED) {
//这里基本上不会到,因为状态还来不及改变
gattServer.close();
mDevices.remove(deviceId);// Only remove

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值