Search code examples
bluetooth-lowenergyrxandroidble

getServiceData returns an empty array in some devices


Context:

I have two devices with me: 1. LG G7 2. Huawei Pra LX1

I am currently using implementation "com.polidea.rxandroidble2:rxandroidble:1.10.0"

When I call to

Disposable scanSubscription = rxBleClient.scanBleDevices(
        new ScanSettings.Builder()
            // .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) // change if needed
            // .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // change if needed
            .build()
        // add filters if needed
)
    .subscribe(
        scanResult -> {
            // Process scan result here.
        },
        throwable -> {
            // Handle an error here.
        }
    );

I am getting different behaviours when I call to getScanRecord().getServiceData() in the scanResults object:

For device #1, I am getting an array with a value (which is correct) For device #2, I am getting an empty array (wrong)

The thing is that I am using a third app (nRF Connect) to see if device #2 has any hardware limitation and I can see the advertising has ServiceData information with 1 result as expected.

Am I doing anything wrong?


Solution

  • You have not mentioned the Android OS versions of your test devices but it seems that they one is Android <8.0 and the other is Android >=8.0.

    What you experience is a simple change of the implementation of Android OS. You can compare how the advertisement data is parsed on Android 7.1 and Android 8.0. Before Android 8.0 advertisement data that contained service data from services with UUIDs longer than 16 bits were not parsed.

    The newer implementation of Android OS advertisement parsing may be backported in the library. I have created an issue for that.