Android beacon Monitoring while Ranging

三世轮回 提交于 2019-12-13 04:34:44

问题


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:


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



来源:https://stackoverflow.com/questions/24008722/android-beacon-monitoring-while-ranging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!