android - Android Beacon Library - How to prevent any ScanJob to run while app is in foreground?
问题描述
I've an app that uses to the android-beacon-library to detect when the smartphone enters in range of some Beacons. After opening the app for the first time and initializing the RegionBootstrap
, I noticed that org.altbeacon.beacon.service.ScanJob
are run by the lib. This seems to cause delays with the app's main Bluetooth scanner, which runs only when the app is in foreground.
Therefore, I'd like the Beacon lib to scan for beacons only when the app is in background, or closed.
What is the best way for implementing this behavior please ?
解决方案
两步:
- 一定要使用 BackgroundPowerSaver
- 设置 beaconManager.setForegroundBetweenScanPeriod(Long.MaxLong)
以上将使得当应用程序处于前台时不会发生库扫描。
推荐阅读
- flutter - Flutter 客户端证书认证
- sql - 如何从具有工作日标志的表中选择下一行
- .net - 从解决方案中的另一个项目启动二进制文件
- javascript - DocuSugn eSignature API 是否支持在 HTML 文档中嵌入地图?
- c++ - 为什么我们在 C++20 中需要 auto after function 概念参数?
- python - 使用model.predict()后如何理解结果数组的维度
- javascript - 覆盖内置 Crud 方法:无法读取未定义的属性“应用”
- azure-cosmosdb - Cosmos DB 本地模拟器 - 模拟的 RU 是什么?
- python - 如何解决意外的 pyinstaller 异常“找不到 pyqt5_plugins 分发”?
- tsql - SQL Server CTE 和递归示例误区