Question

In continuation with my previous question asked here, I am no longer following the approach of creating single Region for all beacons. Now i am creating Regions at run-time. I did ranging first. Below is code that i am trying to implement.

public void onBeaconsDiscovered(Region region, final List<Beacon> beacons) { 
     for(int i =0;i<beacons.size();i++)
     { 
        Region r = new Region("RegionID", beacons.get(i).getProximityUUID(), beacons.get(i).getMajor(), beacons.get(i).getMinor()); 
        try { 
              beaconManager.startMonitoring(r); 
            } catch (RemoteException e) {
                e.printStackTrace(); 
            }
    } 
  } 

  public void onEnteredRegion(Region arg0, List<Beacon> arg1) {
         //Log Data in DB 
  }

  public void onExitedRegion(Region region) { 
     //Log Data in DB 
  }

Is the above mentioned approach correct? The problem is, sometimes, same beacon is entering twice in onEnteredRegion(), without exiting. I have tried to play around with scan interval for foreground and background scan, but things not in sync. I am using Estimote beacon sdk for android.

Was it helpful?

Solution

Problem might be very simple. Your code sample is reusing the same region identifier "RegionID" for all regions. Please use different ones.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top