Detect beacon exited a range

試著忘記壹切 提交于 2019-12-13 04:34:12

问题


I am using Android with the AltBeacon library. I am starting to develop a BLE app which should tell me when a beacon is entering and when it is exiting a range inside a region so I can start an action.

I could detect when a beacon is entering a region and determine his range. Therefore I used the didRangeBeaconsInRegion Method.

My problem is now how to detect that a beacon has left/exited that range in the region? I couldn't find anything in the lib to do so.

How can I achieve this?


回答1:


The Android Beacon Library offers to sets of APIs for looking for beacons:

  1. Ranging APIs. These give you a callback to didRangeBeaconsInRegion approximately every second that beacons of interest are in range, and provides a list of all these beacons so you can inspect their identifiers.

  2. Monitoring APIs. These provide callbacks only when beacons of interest appear didEnterRegion or disappear didExitRegion.

Your question suggests that you have currently implemented the Ranging APIs, and need to implement the Monitoring APIs to know when all beacons of interest disappear.

You can see an example of this in the Monitoring Example Code section at the top of this page.

EDIT: Note that you can monitor regions based on individual beacons and dynamically change which are being monitored. So in the ranging callback you could do something like:

Region singleBeaconRegion = new Region(beacon.toString(), beacon.getIdentifiers());
beaconManager.startMonitoringBeaconsInRegion(singleBeaconRegion);

This will start monitoring for a single beacon matching the passed identifiers. You will get a callback to didExitRegion when it is no longer visible.

If you use this technique, you should also stop monitoring the region on exit, so your monitored region list does not grow large over time:

public void didExitRegion(Region region) {
    // perform logic based on region here
    beaconManager.stopMonitoringBeaconsInRegion(region);
}


来源:https://stackoverflow.com/questions/31494666/detect-beacon-exited-a-range

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