getServiceData在某些设备中返回空数组 [英] getServiceData returns an empty array in some devices
问题描述
上下文:
我有两个设备:1. LG G72.华为Pra LX1
我当前正在使用实现"com.polidea.rxandroidble2:rxandroidble:1.10.0"
当我致电
一次性scanSubscription = rxBleClient.scanBleDevices(新的ScanSettings.Builder()//.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)//如果需要更改//.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)//如果需要更改.建造()//根据需要添加过滤器).订阅(scanResult->{//在这里处理扫描结果.},投掷->{//在此处处理错误.});
当我调用scanResults对象中的getScanRecord().getServiceData()时,我会得到不同的行为:
对于设备#1,我得到一个带有值的数组(正确)对于2号设备,我得到了一个空数组(错误)
问题是,我正在使用第三个应用程序(nRF Connect)来查看设备#2是否具有任何硬件限制,并且可以看到广告中的ServiceData信息具有预期的1个结果.
我做错什么了吗?
您还没有提到测试设备的Android OS版本,但似乎它们一个是Android< 8.0,另一个是Android> = 8.0./p>
您遇到的是对Android OS实现的简单更改.您可以在 Android 8.0 .在Android 8.0之前,未解析包含UUID超过16位的服务中的服务数据的广告数据.
Android OS广告解析的较新实现可能会在库中向后移植.我为此创建了一个问题.
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?
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.
这篇关于getServiceData在某些设备中返回空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!