Android中Altbeacon扫描仪特定的UUID

时间:2019-08-15 15:46:32

标签: android android-studio ibeacon beacon altbeacon

如果我需要监视UUID的特定区域。

在一个区域中声明,但是当输入didEnterRegion时,我仅将UUID以及Major和Minor设置为null,是否需要做didRangeBeaconsInRegion以仅找到定义的区域而不找到另一个不需要的区域?

我将区域定义如下:

Region region = new Region ("region", Identifier.parse ("UUID"), null, null);

另一个问题,图书馆是否按位置找到信标?

非常感谢你, 问候

public void onBeaconServiceConnect() {

    beaconManager.addMonitorNotifier(new MonitorNotifier() {
    @Override
    public void didEnterRegion(Region region) {
        Log.i(TAG, " enter region");
        try {
            beaconManager.startRangingBeaconsInRegion(region);
            Log.i(TAG, "region beacon" + region.getId1() + " " + region.getId2() + " " + region.getId3());
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void didExitRegion(Region region) {
        Log.i(TAG, "I no longer see an beacon");
        try {
            beaconManager.stopRangingBeaconsInRegion(region);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void didDetermineStateForRegion(int state, Region region) {
        Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+ state);
    }

});

try {
      beaconManager.startMonitoringBeaconsInRegion(new 
Region("myMonitoringUniqueId", Identifier.parse("UUID"), null, null));
    } catch (RemoteException e) {

   }
}

1 个答案:

答案 0 :(得分:0)

didEnterRegion回调不会告诉您哪个特定的信标与您的Region定义相匹配。它返回调用Region时使用的startMonitoringBeaconsInRegion对象的副本。如果要获取匹配信标的特定标识符,请使用startRangingBeaconsInRegion(...)并等待对didRangeBeaconsInRegion(...)的回调,该回调将包括所有匹配信标的列表。

API之所以如此工作有很多原因,但最根本的原因是因为该API是根据iOS上等效的CoreLocation API建模的,以实现互操作性,并且它们的工作方式相同。