Search code examples
androidrxandroidble

Read/write ble characteristics from/to particular service


I have several services with different UUIDs, but with the same characteristics UUIDs. I'm not sure what characteristic will be got if I call rxBleConnection.readCharacteristic(UUID). How to do it the best? I can find a particular service from the services list and then deal with BluetoothGattService and its characteristics, but maybe there is another way?


Solution

  • When there is more than one characteristic with the same UUID the only API that allows the user to control which characteristic will be used are:

    • RxBleConnection.readCharacteristic(BluetoothGattCharacteristic)
    • RxBleConnection.writeCharacteristic(BluetoothGattCharacteristic, byte[])
    • RxBleConnection.setupNotification(BluetoothGattCharacteristic)
    • RxBleConnection.setupIndication(BluetoothGattCharacteristic)
    • Other that expose usage of BluetoothGattCharacteristic

    To get a reference to the BluetoothGattCharacteristic the user should search the result of RxBleConnection.discoverServices() — first to get the needed BluetoothGattService and then search the service for the needed BluetoothGattCharacteristic