多次重新连接后 onConnectionStateChange 中的状态为 GATT_FAILURE

Status is GATT_FAILURE in onConnectionStateChange after many reconnections

我正在通过以下方式连接到 ble 设备:

 mBluetoothGatt = device.connectGatt(this.context, false, mGattCallback);

 mBluetoothGatt.disconnect();

但如果我做得很快,那么我会在 mGattCallback

onConnectionStateChange 中收到 status=BluetoothGatt.GATT_FAILURE

然后我无法再次连接到 GATT,即使打开 off/turn 蓝牙。

只有应用强制停止才能解决问题

通过在状态为 STATE_DISCONNECTED

时添加 mBluetoothGatt.close(); 来修复
private final BluetoothGattCallback mGattCallback =
            new BluetoothGattCallback() {
                @Override
                public void onConnectionStateChange(BluetoothGatt gatt, int status,int newState) {
                    String intentAction;

                    if (newState == BluetoothProfile.STATE_CONNECTED) {

                    } else if (status==133&&newState == BluetoothProfile.STATE_DISCONNECTED) {
                        mBluetoothGatt.close();
                    }else if (status==BluetoothGatt.GATT_FAILURE&&newState == BluetoothProfile.STATE_DISCONNECTED){

                    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                        mBluetoothGatt.close();
                    }
                }