Monitoring iBeacons with Altbeacon library
Asked Answered
C

1

5

I am testing the Android Beacon Library from AltBeacon http://altbeacon.github.io/android-beacon-library/index.html

I am monitoring one "generic" region setting only the first id (UUID), and levaing id2, and id3 as null.

Region region = new Region(uuid, Identifier.parse(uuid), null, null);

I receive the didEnterRegion without problems, but i have a question. In didEnterRegion i receive the Region as a parameter, but can i know the concrete beacon that launched the event? I want to know the id1, id2, and id3 of the beacon that launches this event region, is this possible?

Thanks in advance

Coincidence answered 22/8, 2014 at 9:31 Comment(0)
V
9

If you need to know the identifiers of the specific beacons you detected, simply use the ranging APIs. You will get a callback with a Beacon object that contains the identifiers:

beaconManager.setRangeNotifier(this);
beaconManager.startRangingBeaconsInRegion(region);
...

public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
        for (Beacon beacon: beacons) {
            Log.i(TAG, "Beacon detected with id1: "+beacon.getId1()+" id2:"+beacon.getId2()+" id3: "+beacon.getId3());     
        }
}
Varicolored answered 22/8, 2014 at 10:47 Comment(3)
Thanks for your response, but i don't want to be ranging everytime i am monitoring. I suposse that if i do that, i will drain the batteryCoincidence
Good news! You don't need to worry about using extra battery when ranging. The same radio scanning takes place whether you are ranging or not, so ranging is the proper way to read beacon identifiers. The issues with battery come in not with monitoring vs. ranging but with the frequency of the scans. By default, the library does scans constantly when your app is in the foreground, and every five minutes when your app is in the background. See here for details: altbeacon.github.io/android-beacon-library/battery_manager.htmlVaricolored
As the battery_manager article says, this has some limitations since Android 8 and higher. The alternative is also noted in the article, for faster access I copy it here: altbeacon.github.io/android-beacon-library/…Tarrah

© 2022 - 2024 — McMap. All rights reserved.