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

Nic*_*hek 5 android bluetooth bluetooth-lowenergy gatt

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

 mBluetoothGatt = device.connectGatt(this.context, false, mGattCallback);
Run Code Online (Sandbox Code Playgroud)

然后

 mBluetoothGatt.disconnect();
Run Code Online (Sandbox Code Playgroud)

但如果我赶快做,然后我收到status=BluetoothGatt.GATT_FAILUREonConnectionStateChangemGattCallback

即使关闭/打开蓝牙,我也无法再次连接到GATT.

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

Nic*_*hek 4

mBluetoothGatt.close();通过在状态为时添加来修复STATE_DISCONNECTED

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();
                    }
                }
Run Code Online (Sandbox Code Playgroud)