繁体   English   中英

OnePlus Android 设备的 iBeacon 检测会在一段时间内停止

[英]Detecting of iBeacon stops in a while for OnePlus Android device

最初启动应用程序时,信标检测工作正常。 但过了一段时间(没有找到确切的模式,但我们在 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,这意味着(至少我是这么认为的)蓝牙堆栈处于良好状态。 日志也证明了这一点(如下)。

  • 在我们的应用程序中,我们的代码与示例应用程序非常相似: https ://github.com/davidgyoung/android-beacon-library-reference-kotlin

唯一的变化是我们将 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? 我做出这个假设是因为我可以在日志中看到“期待成为 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)

但这对我们也没有帮助。

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

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

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM