【问题标题】:Detecting of iBeacon stops in a while for OnePlus Android deviceOnePlus Android 设备的 iBeacon 检测会在一段时间内停止
【发布时间】:2022-06-16 03:43:14
【问题描述】:

最初启动应用程序时,信标检测工作正常。但过了一段时间(没有找到确切的模式,但我们在 8-16 小时后遇到了它)iBeacons 检测到停止。

  • 我们特别在 OnePlus 8 Pro 设备上检测到该问题,并且可能在其他 OnePlus 设备上发生。

  • 我们正在使用 AltBeacon 库 2.19 版本 实现 'org.altbeacon:android-beacon-library:2.19'

  • 我们试图杀死该应用并重新启动,但这没有帮助,未检测到 iBeacons。

  • 重启 Android 设备有帮助,应用再次开始检测 iBeacons

  • 关闭和打开蓝牙会有所帮助,应用会再次开始检测 iBeacons。

  • 同时,我们添加了一些调试代码,当Beacons检测不起作用时:

添加此代码:

BluetoothMedic.getInstance().runScanTest(context)

它仍然返回 TRUE,这意味着(至少我是这么认为的)蓝牙堆栈处于良好状态。日志也证明了这一点(如下)。

唯一的改变是我们将 Beacons 检测实现封装到 BeaconsManager 中,并通过 Koin 库(Kotlin 依赖注入库)在 Application(继承)类中初始化该管理器对象

  • 我们启用了日志记录:

通过添加此代码:

BeaconManager.setDebug(true)

这是与同一特定信标相关的日志:

a) 成功检测到信标后,我们可以看到以下日志:

03-23 18:25:46.250  2629  2629 D CycledLeScannerForLollipop: got record
03-23 18:25:46.250  2629  2629 D CycledLeScannerForLollipop: with service uuid: 00001308-0000-1000-8000-00805f9b34fb

.... Here, there were some more logs for detection BLE device which is not iBeacon

03-23 18:25:46.286  2629  2629 D CycledLeScannerForLollipop: got record
03-23 18:25:46.286  2629 10587 D BeaconParser: Ignoring pdu type 01
03-23 18:25:46.286  2629 10587 D BeaconParser: Processing pdu type FF: 0201061aff4c00021554656c6c69512069426561636f6e545100010370c40c09432049442030303033373000000000000000000000000000000000000000 with startIndex: 5, endIndex: 29
03-23 18:25:46.286  2629 10587 D BeaconParser: Ignoring pdu type 09
03-23 18:25:46.286  2629 10587 D BeaconParser: Ignoring pdu type 43
03-23 18:25:46.286  2629 10587 D BeaconParser: Ignoring pdu type 30
03-23 18:25:46.286  2629 10587 D BeaconParser: This is a recognized beacon advertisement -- 02 15 seen
03-23 18:25:46.286  2629 10587 D BeaconParser: Bytes are: **0201061aff4c00021554656c6c69512069426561636f6e545100010370c40c09432049442030303033373000000000000000000000000000000000000000**
03-23 18:25:46.287  2629 10587 D m       : Beacon packet detected for: id1: 54656c6c-6951-2069-4265-61636f6e5451 id2: 1 id3: 880 with rssi -96
03-23 18:25:46.287  2629 10587 D m       : beacon detected : id1: 54656c6c-6951-2069-4265-61636f6e5451 id2: 1 id3: 880
03-23 18:25:46.287  2629 10587 D m       : looking for ranging region matches for this beacon
03-23 18:25:46.287  2629 10587 D m       : matches ranging region: id1: 54656c6c-6951-2069-4265-61636f6e5451 id2: null id3: null
03-23 18:25:46.287  2629 10587 D RangeState: adding id1: 54656c6c-6951-2069-4265-61636f6e5451 id2: 1 id3: 880 to new rangedBeacon

b) 当信标检测停止工作时,我们可以看到以下日志:

03-23 15:06:42.795 11304 11304 D CycledLeScannerForLollipop: got record
03-23 15:06:42.795 11304 11304 D CycledLeScannerForLollipop: with service uuid: 0000fe9f-0000-1000-8000-00805f9b34fb

... Here, there were some more logs for detection BLE device which is not iBeacon

03-23 15:06:42.797 11304 11304 D CycledLeScannerForLollipop: got record
03-23 15:06:42.797 11304 22675 D BeaconParser: Ignoring pdu type 01
03-23 15:06:42.797 11304 22675 D BeaconParser: Processing pdu type FF: **0201061aff4c00021554656c6c69512069426561636f6e545100010370c40c09432049442030303033373000000000000000000000000000000000000000** with startIndex: 5, endIndex: 29
03-23 15:06:42.797 11304 22675 D BeaconParser: Ignoring pdu type 09
03-23 15:06:42.798 11304 22675 D BeaconParser: Ignoring pdu type 43
03-23 15:06:42.798 11304 22675 D BeaconParser: Ignoring pdu type 30
03-23 15:06:42.798 11304 22675 D BeaconParser: This is not a matching Beacon advertisement. (Was expecting be ac.  The bytes I see are: 0201061aff4c00021554656c6c69512069426561636f6e545100010370c40c09432049442030303033373000000000000000000000000000000000000000
0

所以,从日志中我可以看到该库实际上能够检测到 BLE 设备,但由于某种原因,该库似乎会重置信标解析器布局,并且只解析默认的 AltBeacons?我做出这个假设是因为我可以在日志中看到“Was expecting be ac”

在信标管理器设置中,我们有以下代码:

beaconManager.beaconParsers.clear()
beaconManager.beaconParsers.add(BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:27-28,d:29-29"))

作为一种解决方法,我们还尝试在每次测距开始之前将代码放在上面:

beaconManager.startRangingBeacons(region)

但这对我们也没有帮助。

【问题讨论】:

    标签: android ibeacon altbeacon ibeacon-android android-ibeacon


    【解决方案1】:

    在我看来,OnePlus 正在杀死您的应用程序,然后应用程序以某种方式在后台重新启动,但是当它执行时,设置信标解析器的代码永远不会执行。这会导致您最初设置的信标解析器丢失。

    了解为什么会发生这种情况的一些提示:

    1. 如果您还没有 Android Application 类,请添加一个并记录一些内容并在 onCreate 方法中记录时间戳。这将告诉您在检测停止时您的应用是否重新启动。

    2. 考虑将您的初始化转移到上述方法,或者我是否从上述方法执行另一个类,以确保它在每次应用启动时执行。

    3. 在 beaconManager.getBeaconParsers() 中记录每个项目,我会看到您的应用何时丢失您设置的项目。

    2022 年 6 月 15 日更新:库版本 2.19.5-beta5 添加了changes 以帮助防止这种情况发生。

    【讨论】:

    • 谢谢大卫!听起来很合理,我会尝试你的建议。
    • 你好@davidgyoung!我们将库更新为 2.19.5-beta5,经过 4 天的测试,我们可以确认问题已经消失。信标测距继续正常工作。根据提交,2.19.5-beta5 版本解决了 Beacons 在不同线程中解析的问题。谢谢!
    • 很高兴听到!我已通过库中更改的链接更新了我的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多