How to detect when the user has exited a beacons range


We have an application that has a background service that monitors for beacons with our UUID. When it detects that there is atleast one beacon in range, it invokes a broadcast receiver that starts ranging. This part works fine.

The idea is that when the user walks out of the range of a beacon, we need to log an event in database and if there are no more beacons left to range then switch from ranging to monitoring.

The listener for ranging only defines the onBeaconsDiscovered method. So when you are ranging and detect one or more beacons, how do you tell if the user has exited a beacons range. I have tested and as I walk out of beacons range, depending on how fast I walk, I may go from Immediate zone to getting a callback with an empty list of beacons.

Any help will be appreciated.

Waqar Sadiq

As long as the beacon is in range, it’ll be reported to the onBeaconsDiscovered method. Once you exit the range, it disappears from the list of beacons reported to that method.

Alternatively, you can use monitoring alongside ranging, and use ranging for whatever you’re using it now, and monitoring for the onExitedRegion callback.