I have read a lot of information regarding the foreground/background scan periods and issues for long scans on Android 7 but I am confused as to what should be configured for best results in the latest alt-beacon library ( 2.15.4 ).
We have implemented a foreground service and bootstrapping and require the library to do the following:
App in Foreground scan for 1100ms, sleep 0 ms
App in Background scan and 1100ms, sleep 10000ms
We are aware that there will be edge cases when beacons are not detected due to start/stop scanning but would prefer this over the potential of the app scanning being killed by the OS due to long running scans.
What setForeground... setBackground... values should be used for the above requirements? OR should we not use these methods and just use the defaults?
Will this cause the "Scanning to frequently" issue and how would we get around this with settings as close as possible to our requirements?
答案 0 :(得分:0)
执行以下操作,您描述的扫描速率将可在大多数手机上使用:
beaconManager.setForegroundScanPeriod(1100); // Default, so this line not needed
beaconManager.setForegroundBetweenScanPeriod(0); // Default, so this line not needed
beaconManager.setBackgroundScanPeriod(1100);
beaconManager.setBackgroundBetweenScanPeriod(10000);
BackgroundPowerSaver bps = new BackgroundPowerSaver();
但是,在Android 8+上,操作系统将两次扫描之间的时间限制为大约15分钟。如果您不能接受,那么唯一的选择就是指示库使用foreground service。如果您确实配置了前台服务,那么即使在Android 8+上,也可以获得所需的确切背景扫描速率。
我说这可以在“大多数手机”上使用,因为大型中国制造商(例如,华为,OnePlus,小米)已从2017年底开始分叉其Android版本,以实现积极的节能功能,这些功能可在后台阻止信标扫描。专有的分叉要么在屏幕关闭时阻止扫描(华为请参阅here和here)(小米请参见here),要么阻止前台服务(OnePlus请参见here)。这些有效地破坏了Android应用在其操作系统分支上的正常运行。