-1

想要这样做:

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

4

1 回答 1

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
         }   
}
于 2014-12-02T16:33:38.197 回答