想要这样做:
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
}
}
问题是当调用get.Id1时,该值返回null而不必区分信标
答案 0 :(得分:1)
您只需使用测距API即可获取可见信标的特定标识符。您可以在didEnterRegion
回调中开始测距,并且您将使用带有标识符的其他方法获得回调。像这样:
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
}
}