0

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?

GraphicsMuncher
  • 4,583
  • 4
  • 35
  • 50
egmontr
  • 249
  • 3
  • 15

1 Answers1

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);
}
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Thanks for answering @davidgyoung. I know the two described APIs. My problem is, that when I use the Monitoring API, I only can monitor the entering and exiting of specific region, but not a specific beacon within his range! I want to know, when **one** beacon of interest disappear and not all beacons. Is that possible? – egmontr Jul 19 '15 at 06:09
  • Thanks @davidgyoung. It works, but the app often switches between Enter and Exit. But since I want to start various actions when entering and exiting, this actions are executed more than once. The tip to stop the monitoring, I can not follow, otherwise exiting would not be reported. Do you have any idea here? Also I'd like to just start actions if: - A predetermined radius was entered. This works if I start ranging for the regions. - The radius was exited. I do not see how I could make this work. – egmontr Jul 28 '15 at 10:22
  • Enter/exit will happen muliple times beacause you are still ranging. If you want to suppress multiple events, I would simply set a flag variable after triggering the event, and if the flag is already set, don't execute the logic the next time. If you want to trigger by distance, I would open a new question, as there is not room to describe how to do this in comments. – davidgyoung Jul 28 '15 at 12:27