Android OS 9.0 , BLE 5.0 specific issue fetching list of services from BluetoothGatt

  • Thread starter Android Central Question
  • Start date
A

Android Central Question

Developed the following source code for sending message from one Android device to another Android device using BLE: '

public static String SERVICE_STRING = "6exxxxxx-xxxx-xxxx-xxxx-xxxxxdcca9e";

public static String CHARACTERISTIC_ECHO_STRING = "6eyyyyyy-yyyy-yyyy-yyyy-yyyyycca9e";

List serviceList = bluetoothGatt.getServices(); On checking the list of services , on Realme 5 Pro(Android OS 9.0 , BLE v5.0) after a successful connection is established with another device, the list of services is not returning the specific service with service string as mentioned above , hence the following code(BluetoothGattService) is returned as null , so unable to send data to another device via BLE.

BluetoothGattService service = findService(serviceList);
if (service == null) {
Log.i("Null service", "Null service.");
return matchingCharacteristics;
}
private static BluetoothGattService findService(List<BluetoothGattService> serviceList) {
for (BluetoothGattService service : serviceList) {
String serviceIdString = service.getUuid()
.toString();
if (matchesServiceUuidString(serviceIdString)) {
return service;
}
}
return null;
}
private static boolean matchesServiceUuidString(String serviceIdString) {
return uuidMatches(serviceIdString, SERVICE_STRING);
}
The same source code is returning the list of services with the mentioned service string for other devices like Mi 4a(Android OS 7.0 , BLE 4.0) , Realme 3i(Android OS 9.0, BLE 4.2) and for them , the BluetoothGattService instance is returning the details which is not null and hence able to send messages to other devices.

Did anyone face the same issue with device with Android OS v9.0 and BLE v5.0 ?