I\'m building an app with Android Studio that can read the value from a device BLE. This device, have 4 services. The fourth services have 3 characteristic. I want to read t
You can achive multiple reads with the following code: First create a List
private int ReadQueueIndex;
private List ReadQueue;
In onServicesDiscovered
add characteristics in ReadQueue:
ReadQueue = new ArrayList<>();
ReadQueue.add(characteristicsList.get(2));
ReadQueue.add(characteristicsList.get(1));
ReadQueue.add(characteristicsList.get(0));
ReadQueueIndex = 2;
ReadCharacteristics(ReadQueueIndex);
Create ReadCharacteristics
method
private void ReadCharacteristics(int index){
bluetoothGatt.readCharacteristic(ReadQueue.get(index));
}
Then in your onCharacteristicRead
callback:
String value = Arrays.toString(characteristic.getValue());
if(characteristic.getUuid().equals(characteristicsList.get(0).getUuid())){
Log.i("Characteristic 0:", value);
} else if(characteristic.getUuid().equals(characteristicsList.get(1).getUuid())){
Log.i("Characteristic 1:", value);
} else if(characteristic.getUuid().equals(characteristicsList.get(2).getUuid())){
Log.i("Characteristic 2:", value);
}
ReadQueue.remove(ReadQueue.get(ReadQueueIndex));
if (ReadQueue.size() >= 0) {
ReadQueueIndex--;
if (ReadQueueIndex == -1) {
Log.i("Read Queue: ", "Complete");
}
else {
ReadCharacteristics(ReadQueueIndex);
}
}
Hope its helpful.