The Android Beacon Library offers to sets of APIs for looking for beacons:
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.
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);
}