@Override
  public void didEnterRegion(Region arg0) {
    // In this example, this class sends a notification to the user whenever a Beacon
    // matching a Region (defined above) are first seen.
    System.out.println("\nENTERED!!!\n");
    Log.d(TAG, "did enter region.");

    Log.d(TAG, "Sending notification. [" + arg0.getUniqueId() + "]");
    sendNotification(arg0.getUniqueId());

    if (!haveDetectedBeaconsSinceBoot) {
      Log.d(TAG, "auto launching MainActivity");

      // The very first time since boot that we detect an beacon, we launch the
      // MainActivity
      Intent intent = new Intent(this, MainActivity.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      // Important:  make sure to add android:launchMode="singleInstance" in the manifest
      // to keep multiple copies of this activity from getting created if the user has
      // already manually launched the app.
      this.startActivity(intent);
      haveDetectedBeaconsSinceBoot = true;
    } else {
      if (specifyViewActivity != null) {
        Log.d(TAG, "specifyViewActivity is not null");
        // If the Monitoring Activity is visible, we log info about the beacons we have
        // seen on its display
        // specifyViewActivity.logToDisplay("I see a beacon again" );
      } else {
        Log.d(TAG, "specifyViewActivity is null");
        // If we have already seen beacons before, but the monitoring activity is not in
        // the foreground, we send a notification to the user on subsequent detections.
      }
    }
  }
Esempio n. 2
0
 /**
  * Method that returns the current {@link ProximityData} object informations as a the
  * corresponding {@link POI} object
  *
  * @return
  */
 public POI asPOI() {
   POI ret = new POI();
   String UUID =
       this.BLERegion.getId1()
           + (BLERegion.getId1() == null ? "" : ":" + BLERegion.getId1())
           + (BLERegion.getId2() == null ? "" : ":" + BLERegion.getId2());
   ret.setBeaconUuid(UUID);
   ret.setName(ID);
   ret.setLatitude(latitude);
   ret.setLongitude(longitude);
   ret.setRadius(radius);
   return ret;
 }
Esempio n. 3
0
 /**
  * Called with a state value of MonitorNotifier.INSIDE when at least one beacon in a Region
  * is visible. Called with a state value of MonitorNotifier.OUTSIDE when no beacons in a
  * Region are visible.
  */
 @Override
 public void didDetermineStateForRegion(int state, Region region) {
   LogManager.d(
       TAG,
       "didDetermineStateForRegion() ,region uniqueId= "
           + region.getUniqueId()
           + " state="
           + (state == 1 ? "inside" : "outside"));
 }
 @Override
 public void didEnterRegion(Region region) {
   Log.d(TAG, "I just saw a beacon named " + region.getUniqueId() + " for the first time!");
   try {
     Log.d(TAG, "entered region.  starting ranging");
     mBeaconManager.startRangingBeaconsInRegion(mAllBeaconsRegion);
     mBeaconManager.setRangeNotifier(this);
   } catch (RemoteException e) {
     Log.e(TAG, "Cannot start ranging");
   }
 }
Esempio n. 5
0
 /** Called when no beacons in a Region are visible. */
 @Override
 public void didExitRegion(Region region) {
   LogManager.d(TAG, "didExitRegion(),region uniqueId= " + region.getUniqueId());
   /**
    * Tells the BeaconService to stop looking for beacons that match the passed Region object
    * and providing mDistance information for them.
    */
   try {
     mBeaconManager.stopRangingBeaconsInRegion(ALL_VOLIAM_BEACONS_REGION);
   } catch (RemoteException e) {
     LogManager.d(TAG, "RemoteException:" + e.toString());
   }
 }
 public void handleExitedRegion(org.altbeacon.beacon.Region region) {
   if (isMonitoringRegion(region)) {
     String uuid = region.getId1() != null ? region.getId1().toString() : "";
     String major = region.getId2() != null ? region.getId2().toString() : "";
     String minor = region.getId3() != null ? region.getId3().toString() : "";
     this.beaconManager.stopMonitoringRegion(new Region(this.regionName, uuid, major, minor));
     this.inRegion = false;
     callback.whenExited(this.regionName);
   }
 }
Esempio n. 7
0
 /** Called when at least one beacon in a Region is visible. */
 @Override
 public void didEnterRegion(Region region) {
   LogManager.d(TAG, "didEnterRegion(),region uniqueId= " + region.getUniqueId());
   /**
    * 启动测距修正 Tells the BeaconService to start looking for beacons that match the passed
    * Region object, and providing updates on the estimated mDistance every
    * seconds(实际上是每个扫描周期) while beacons in the Region are visible. Note that the Region's
    * unique identifier must be retained to later call the stopRangingBeaconsInRegion method.
    * this will provide an update once per second with the estimated distance to the beacon
    * in the didRAngeBeaconsInRegion method.
    */
   try {
     mBeaconManager.startRangingBeaconsInRegion(ALL_VOLIAM_BEACONS_REGION);
   } catch (RemoteException e) {
     LogManager.d(TAG, "RemoteException:" + e.toString());
   }
 }
 @Override
 public void didExitRegion(Region region) {
   Log.d(TAG, "I no longer see a beacon named " + region.getUniqueId());
 }
  private boolean isMonitoringRegion(org.altbeacon.beacon.Region region) {

    if (region != null && currentMonitoredRegion != null) {
      String id1 = region.getId1() != null ? region.getId1().toString() : "";
      String id2 = region.getId2() != null ? region.getId2().toString() : "";
      String id3 = region.getId3() != null ? region.getId3().toString() : "";

      String currentId1 =
          currentMonitoredRegion.getId1() != null ? currentMonitoredRegion.getId1().toString() : "";
      String currentId2 =
          currentMonitoredRegion.getId2() != null ? currentMonitoredRegion.getId2().toString() : "";
      String currentId3 =
          currentMonitoredRegion.getId3() != null ? currentMonitoredRegion.getId3().toString() : "";

      return (id1.equals(currentId1) && id2.equals(currentId2) && id3.equals(currentId3));
    } else {
      return false;
    }
  }