getServiceData returns an empty array in some devices

风格不统一 提交于 2021-01-29 11:05:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/56657558/getservicedata-returns-an-empty-array-in-some-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!