I think the reason because scanPeroid is too short, Is there a way I can set the scan Period(for example 2 seconds) when app is in foreground(not foreground service)?
I tried this code, and it scan every 5 second and can observed beacons every time. However, it only works when app is in background.
My mistake, I added this code, the problem is solved:
setupForegroundService()
beaconManager.foregroundScanPeriod=2000L
beaconManager.foregroundBetweenScanPeriod=1000L
I run the test code and when the app is in foreground, it will observe beacons every 1 second, the log is like below:
Ranged: 1 beacons Ranged: 0 beacons Ranged: 1 beacons Ranged: 0 beacons Ranged: 1 beacons Ranged: 0 beacons .............
I think the reason because scanPeroid is too short, Is there a way I can set the scan Period(for example 2 seconds) when app is in foreground(not foreground service)?
I tried this code, and it scan every 5 second and can observed beacons every time. However, it only works when app is in background.
// setupForegroundService() // beaconManager.setEnableScheduledScanJobs(false); // beaconManager.setBackgroundBetweenScanPeriod(2000); // beaconManager.setBackgroundScanPeriod(3000);