0

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?

yogeshhkumarr
  • 306
  • 1
  • 16

2 Answers2

1

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.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Thanks a ton! I did mentioned the library i am using, i am working on Estimote library. Can you please share a sample code how we can combine ranging and monitoring in android using estimote library. or should i use open source library. A sample code will be very helpful. – yogeshhkumarr May 29 '14 at 14:43
  • Got it. I read that you were using Estimote beacons, which are iBeacon compatible so they do work with the Android iBeacon Library. See edits for links to sample code of ranging and monitoring. – davidgyoung May 29 '14 at 15:09
  • I have tried your suggestion of combining ranging and monitoring. My scenario is : I am doing ranging first. It is giving me list of beacons in range. Then in onBeaconsDiscovered i am creating a Region for all the beacons that i have discovered. Then I start monitoring that region. It will give me callbacks for onEnteredRegion() and onExitedRegion(). Problem is, sometimes, same beacon is entering twice in onEnteredRegion(), without exiting. I have tried to play around with scan interval for foreground and background scan, but things not in sync. – yogeshhkumarr Jun 02 '14 at 13:10
  • I'd probably have to see your code that sets up these monitored regions upon ranging to make more suggestions. It is possible to have overlapping regions (e.g. if two regions have the same ProximityUUID) that would cause the behavior you describe. – davidgyoung Jun 02 '14 at 13:19
  • I am doing something like this: public void onBeaconsDiscovered(Region region, final List beacons) { for(int i =0;i arg1) { //Log Data in DB } public void onExitedRegion(Region region) { //Log Data in DB } – yogeshhkumarr Jun 02 '14 at 13:38
  • Started new thread for question on scan intervals here:http://stackoverflow.com/questions/24008722/android-beacon-monitoring-while-ranging – yogeshhkumarr Jun 03 '14 at 06:49
0

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.

Wiktor Gworek
  • 486
  • 3
  • 7
  • I understand that onEnteredRegion will give me List of beacons, but my problem is, i need to get the list of beacons in onExitedRegion(Region region), which only give Region region. – yogeshhkumarr May 30 '14 at 05:03
  • Ah, right. You can hold beacons which triggered onEnteredRegion. But this list can be totally misleading in onExitRegion event. Consider following scenario: 1) Beacons A and B share the same proximity UUID and you monitor just this proximity UUID. 2) Beacon A triggers onEnterRegion, than B is around and A is lost. When B is lost onExitRegion is triggered. Is this something you are interested in? – Wiktor Gworek May 31 '14 at 17:33