BleManager.getInstance().disconnect(bleDevice)无效
在使用 BluetoothDevice.connectGatt() 或者 BluetoothGatt.connect() 等建立 BluetoothGatt 连接的时候,有部分手机,在任何时刻都只能最多一个设备在尝试建立连接。如果同时对多个蓝牙设备发起建立 Gatt 连接请求。如果前面的设备连接失败了,后面的设备请求会被永远阻塞住,不会有任何连接回调。
于是我想着是调用disConnect去释放上一个连接,发现并不能释放当前连接,除非超时了,他才会释放。
请问怎么修改呢? @Jasonchenlijian
我看了一下源码进行了如下修改: MultipleBluetoothController类方法: public synchronized void disconnect(BleDevice bleDevice) { if (isContainDevice(bleDevice)) { getBleBluetooth(bleDevice).disconnect(); } } 修改为: public synchronized void disconnect(BleDevice bleDevice) { if (isContainDevice(bleDevice)) { getBleBluetooth(bleDevice).disconnect(); } else { BleBluetooth a = getBleTempBluetooth(bleDevice); if (a != null) { a.noTimeOut(); } } }
添加方法: public synchronized BleBluetooth getBleTempBluetooth(BleDevice bleDevice) { if (bleDevice != null) { if (bleTempHashMap.containsKey(bleDevice.getKey())) { return bleTempHashMap.get(bleDevice.getKey()); } } return null; }
BleBluetooth类添加方法: public synchronized void noTimeOut(){ mainHandler.removeMessages(BleMsg.MSG_CONNECT_OVER_TIME); Message message = mainHandler.obtainMessage(); message.what = BleMsg.MSG_CONNECT_OVER_TIME; mainHandler.sendMessage(message); }
@Jasonchenlijian 希望修改