0
votes

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.

1
You really shouldn't create a large number of regions - you'll get away with it with android clients, but iOS devices will only be able to look for a limited number of regions, so your approach locks your system into being android-only, for essentially no gain. As far as android is concerned, the whole packet it just arbitrary data, so you might as well assign the region and major/minor portions in an iDevice compatible way rather than the basically iDevice-incompatible lots-of-regions scheme you have chosen here.Chris Stratton
@ChrisStratton: The problem with creating single Region for all beacons is - I am not getting onExitedRegion() callback, unless all beacons of that Region, actually exit. And we are planning to test on more than 500 beacons!. Please let me know if there is any other approach which is more optimized.yogeshhkumarr
On Android, this is implemented entirely within code you contril, so you can fix that at the source. Don't use the vendor library if it is a source of difficulty. But you may not want to depend on exiting a region anyway.Chris Stratton
I am trying to calculate the average duration stay of a person within the region. My understanding is I can achieve that by logging time in Entered and Exited Region and calculating duration. That's the only reason I want to listen to onExitedRegion callback. Correct me if my approach is wrong.yogeshhkumarr

1 Answers

1
votes

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