Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status is GATT_FAILURE in onConnectionStateChange after many reconnections

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

like image 605
NickUnuchek Avatar asked Mar 11 '16 08:03

NickUnuchek


1 Answers

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();
                    }
                }
like image 121
NickUnuchek Avatar answered Nov 19 '22 00:11

NickUnuchek