识别方法中的信标didEnterRegion(Region region)和didExitRegion(Region region)

时间:2014-12-02 11:26:52

标签: ibeacon altbeacon

想要这样做:

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而不必区分信标

1 个答案:

答案 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
         }   
}
相关问题