首页 > 解决方案 > 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 ?

标签: androidandroid-bluetoothbeaconaltbeacon

解决方案


两步:

  1. 一定要使用 BackgroundPowerSaver
  2. 设置 beaconManager.setForegroundBetweenScanPeriod(Long.MaxLong)

以上将使得当应用程序处于前台时不会发生库扫描。


推荐阅读