Can I get beacons data in Exit Regions also how can I detect when new beacon enterered into the region?

人盡茶涼 提交于 2019-12-12 15:07:51

问题


When multiple beacons are detected in the regions,

how can I find that which one is the newest detected one?

Also in beacon exist how can I know that specific beacon has left the region.


回答1:


The typical way to solve this is to combine beacon monitoring and beacon ranging.

You use beacon ranging to read the individual identifiers, and keep a map of what beacons have been seen before like this:

private HashSet<Beacon> beaconsSeen = new HashSet<Beacon>();
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {]
    for (Beacon beacon : beacons) {
        if (!beaconsSeen.contains(beacon)) {
            beaconsSeen.add(beacon);
            // Perform your logic here
        }
    }
}

Since you want the logic to trigger again if the beacon is later rediscovered after all beacons in the region disappear, you must clear the map on region exit:

@Override
public void didExitRegion(Region region) {
    beaconsSeen.clear();
}


来源:https://stackoverflow.com/questions/39849297/can-i-get-beacons-data-in-exit-regions-also-how-can-i-detect-when-new-beacon-ent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!