Skip to content

Commit 4b8c99d

Browse files
committed
修改断开逻辑
1 parent 06c894a commit 4b8c99d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

android/src/main/java/com/pauldemarco/flutterblue/FlutterBluePlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ public void onMethodCall(MethodCall call, Result result) {
227227
BluetoothGatt gattServer = mGattServers.remove(deviceId);
228228
if(gattServer != null) {
229229
gattServer.disconnect();
230+
gattServer.close();
231+
gattServer = null;
230232
}
231233
result.success(null);
232234
break;
@@ -703,6 +705,9 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState
703705
if(newState == BluetoothProfile.STATE_DISCONNECTED) {
704706
if(!mGattServers.containsKey(gatt.getDevice().getAddress())) {
705707
gatt.close();
708+
}else{
709+
mGattServers.remove(gatt.getDevice().getAddress());
710+
gatt.close();
706711
}
707712
}
708713
invokeMethodUIThread("DeviceState", ProtoMaker.from(gatt.getDevice(), newState).toByteArray());

lib/src/bluetooth_device.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class BluetoothDevice {
2727
..androidAutoConnect = autoConnect;
2828

2929
Timer timer;
30+
3031
if (timeout != null) {
3132
timer = Timer(timeout, () {
3233
disconnect();

0 commit comments

Comments
 (0)