user3286543
user3286543

Reputation: 21

get BluetoothGattCharacteristic given UUID

I'm wondering what's the best way to retrieve a BluetoothGattCharacteristic if I have the UUID and have successfully connected to the BLE device? For instance, see below. TIA.

public BluetoothGattCharacteristic retrieveCharacteristic(UUID myUUID) {

    BluetoothGattCharacteristic returnChar;
    BluetoothGattService myService;

    myService = mBluetoothGatt.getService(myUUID);
    returnChar = myService.getCharacteristic(myUUID);
    return returnChar;
}

Upvotes: 1

Views: 1830

Answers (1)

Emil
Emil

Reputation: 18497

You need to know what service the characteristic is in in order to retrieve it by uuid. If you don't know which service you can just loop through them with https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#getServices() and then check each service for a characteristic with your uuid.

Upvotes: 1

Related Questions