7

I'm connecting to ble device by:

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

and than

 mBluetoothGatt.disconnect();

but if I'm doing it quickly then I receive status=BluetoothGatt.GATT_FAILURE in onConnectionStateChange of mGattCallback

and then I can't connect to GATT again, even if turn off/turn on Bluetooth.

Only Force Stop of the app can solve the problem

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138

1 Answers1

4

Fixed by adding mBluetoothGatt.close(); when state is 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();
                    }
                }
NickUnuchek
  • 11,794
  • 12
  • 98
  • 138