-1

want to do this:

public void didEnterRegion(Region region) {
    if(region.getId1.equals("xxxxxxxxxxxxx")){
     //display message: welcome to area 1
    } else if(region.getId1.equals("yyyyyyyyy")){
     //display message: welcome to area 2
    }  
}

the problem is that when calling get.Id1 the value returns null and not have to differentiate beacons

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103

1 Answers1

1

You simply need to use the ranging APIs in order to get the specific identifiers of the visible beacons. You can start ranging inside the didEnterRegion callback, and you will get a callback in a different method with the identifiers. Like this:

public void didEnterRegion(Region region) {
       beaconManager.setRangeNotifier(this);
       beaconManager.startRangingBeaconsInRegion(region);
}

public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
        for (Beacon beacon: beacons) {
            if(beacon.getId1().toString().equals("xxxxxxxxxxxxx")){
                //display message: welcome to area 1
            } else if(region.getId1().toString().equals("yyyyyyyyy")){
                //display message: welcome to area 2
         }   
}
davidgyoung
  • 63,876
  • 14
  • 121
  • 204