Android BLE Gatt connection change statuses

Ijas Ahamed N picture Ijas Ahamed N · Jul 12, 2017 · Viewed 14.8k times · Source

I have an android app to connect to a BLE device and write to it. I can successfully connect, read and write to it. As a part of testing, we are trying different disconnection scenarions.

Sometimes, if ble device disconnect the connection, i get the connection change as disconnect with status value as 19. Also if there is any bond error, status equals 22. If i programmatically disconnect the connection, this status gives me 0. But none of these states except 0 are specified in android documentation.

Posting a sample BluetoothGattCallback

private BluetoothGattCallback bluetoothGattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        Log.i(TAG, "onConnectionStateChange status: "+status+", newState: "+newState);
        /*i need to know the posiible values for this status variable*/
        if(newState == BluetoothProfile.STATE_CONNECTED) {
            gatt.discoverServices();
        } else {
            gatt.close();
        }
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        Log.i(TAG, "onServicesDiscovered service discovered");
    }
};

Does anyone faced this same problem and sorted out the list of statuses. I need to know the possible values for status variable in onConnectionStateChange method

Answer

Ijas Ahamed N picture Ijas Ahamed N · Jul 21, 2017

Here is the list of codes i have

  • Programmatically disconnected - 0
  • Device went out of range - 8
  • Disconnected by device - 19
  • Issue with bond - 22
  • Device not found - 133(some phone it gives 62)

I have tested disconnect scenario's in 5.0.2, 5.1, 6.0 and 6.0.1. But only found this bond issue code in 6.0.1 android version.