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

@[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 it after close
}
}
result.success(null);
break;
}
line 861:
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
log(LogLevel.DEBUG, "[onConnectionStateChange] status: " + status + " newState: " + newState);
if(newState == BluetoothProfile.STATE_disCONNECTED) {
String deviceid=gatt.getDevice().getAddress()
if(!mDevices.containsKey(deviceid)) {
//这里才是
gatt.close();
mDevices.remove(deviceid);// Only remove it after close
}
}
invokeMethodUIThread(“DeviceState”, Protomaker.from(gatt.getDevice(), newState).toByteArray());
}

相关文章

这篇文章主要讲解了“FlutterComponent动画的显和隐怎么实现...
这篇文章主要讲解了“flutter微信聊天输入框功能如何实现”,...
本篇内容介绍了“Flutter之Navigator的高级用法有哪些”的有...
这篇文章主要介绍“Flutter怎么使用Android原生播放器”,在...
Flutter开发的android端如何修改APP名称,logo,版本号,具体...
Flutter路由管理初识路由概念一.路由管理1.1.Route1.2.Mater...