/** * Sets the duration in milliseconds spent not scanning between each Bluetooth LE scan cycle when * no ranging/monitoring clients are in the background. default 5 minutes * * @param p (ms) */ public void setBackgroundBetweenScanPeriod(long p) { mBeaconManager.setBackgroundBetweenScanPeriod(p); try { mBeaconManager.updateScanPeriods(); // 保证在下一个循环扫描周期生效 } catch (RemoteException e) { LogManager.d(TAG, "RemoteException:" + e.toString()); } }
@Override public void onActivityStopped(Activity activity) { if (activity instanceof ScannerActivity) { isScannerActivityResumed = false; scannerActivityDestroyedTimestamp = SystemClock.elapsedRealtime(); long delayBetweenScans = getDelayBetweenScans(); Timber.d("setBackgroundBetweenScanPeriod to %d ", delayBetweenScans); beaconManager.setBackgroundBetweenScanPeriod(delayBetweenScans); beaconManager.setBackgroundMode(true); Timber.d("setBackgroundMode"); } }
@Override public void onActivityResumed(Activity activity) { ++this.activeActivityCount; if (activity instanceof ScannerActivity) { beaconManager.setBackgroundMode(false); isScannerActivityResumed = true; // the scanner activity runs in foreground mode, fast scanning Timber.d("setForegroundMode"); } else { // the app is still active but scan is backgrounded indefinitely beaconManager.setBackgroundBetweenScanPeriod(DELAY_FOREVER); isScannerActivityResumed = false; Timber.d("setBackgroundBetweenScanPeriod to %d ", DELAY_FOREVER); beaconManager.setBackgroundMode(true); Timber.d("setBackgroundMode"); } }