@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");
   }
 }
 @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 onBeaconServiceConnect() {
    // callback for when service connection is complete

    mBeaconManager.setBackgroundMode(true);
  }
 public void pause() {
   this.monitoring = false;
   beaconManager.setBackgroundMode(true);
 }
 public void resume() {
   this.monitoring = true;
   beaconManager.setBackgroundMode(false);
 }
示例#6
0
 /**
  * This method notifies the beacon service that the application is either moving to background
  * mode or foreground mode.
  *
  * @param backgroundMode true indicates the app is in the background
  */
 public void setBackgroundMode(boolean backgroundMode) {
   mBeaconManager.setBackgroundMode(backgroundMode);
 }