In Android, How to get ibeacon details onExitedReg

2019-09-03 07:12发布

I am working on android application with Estimote beacons. I am trying to work on a scenario where i will be using more than 100 beacons. For this, instead of creating separate Region for each beacon, I am creating single Region by assigning common Proximity UUID for all beacons and declaring Region by passing Proximity UUID only. I am keeping Major and Minor for uniquely identifying the beacons.

Since my application has to be in background, I am using BeaconManager.MonitoringListener interface with onEnteredRegion and onExitedRegion callbacks(My understanding is Ranging can only be done when application is in foreground). Since, onExitedRegion does not provide me any List of beacons that triggered onExitedRegion, how can I get beacon details, like Major, Minor in onExitedRegion?

2条回答
放荡不羁爱自由
2楼-- · 2019-09-03 07:52

In Estimote SDK MonitoringListener has method onEnteredRegion(Region region, List<Beacon> beacons). Where beacons is a list of beacons that triggered onEnteredRegion event. This list may not reflect all beacons around that are matching given region.

In order to have more precise list of beacons you need to start ranging in onEnteredRegion callback.

查看更多
做自己的国王
3楼-- · 2019-09-03 08:11

EDIT: The library mentioned below has been replaced by the Android Beacon Library. Code samples are available on the same site.


You do not say what library you are using, but the open source Android iBeacon Library allows you to do this by combining ranging and monitoring. The library has no restriction on using ranging in the background (unlike iOS). The library is fully compatible with any standard iBeacon.

Although the library's didExitRegion callback does not tell you the specific beacon that disappeared, you can keep track of these visible beacons based on the list passed to you in the most recent didRangeBeaconsInRegion callback. That way, when you get the didExitRegion callback, you know which beacons were last visible before they all disappeared.

Samples of both ranging and monitoring code are available here.

查看更多
登录 后发表回答