0

I have seen some examples how to get the URL frame of the Eddystone beacon by ranging but not by monitoring

beaconManager.setRangeNotifier(new RangeNotifier() {
    @Override
    public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
        for (org.altbeacon.beacon.Beacon beacon: beacons) {
            if (beacon.getServiceUuid() == 0xfeaa && beacon.getBeaconTypeCode() == 0x10) {
                // This is a Eddystone-URL frame
                String url = UrlBeaconUrlCompressor.uncompress(beacon.getId1().toByteArray());
                Log.d("Eddystone", "I see a beacon transmitting a url: " + url +
                        " approximately " + beacon.getDistance() + " meters away.");
            }
        }
    }
});

on didRangeBeaconsInRegion there is a org.altbeacon.beacon.Beacon parameter. But for monitoring the didEnterRegion only has the Region as the parameter.

 @Override
 public void didEnterRegion(Region region) {

 }

So, how do I get the url of the eddysone beacon on monitoring mode ? Is it possible?

bman
  • 3,740
  • 9
  • 34
  • 40

1 Answers1

1

You must use ranging APIs to read the actual identifier. While it is possible to use monitoring to detect a Eddystone-URL beacon transmission, because the frame has only a single identifier (the URL), you must monitor based on knowing that URL identifier up front (not very useful), or monitor all identifiers.

In the latter case, this creates the problem of reading the identifier since the monitoring callback only has the region object as you describe.

The solution is to range at the same time as you monitor. The ranging callbacks will give you the full list of beacons detected and give you access to the URLs.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • I would want to create a list of beacons nearby and remove them from the list when away. I can only think of doing this using monitoring, adding that url to a list on enter and delete them on exit. Is there any other way? or a correct way of doing this? – bman Jul 17 '16 at 13:44
  • Yes, you could start monitoring for a specific detected URL after finding it by ranging -- based on a region defined in the ranging callback by beacon.getId1(). When you get the exit callback from monitoring, you know the individual beacon has disappeared. Just be sure you set the Region's sting identifier to something unique like beacon.getId1().toSring() – davidgyoung Jul 17 '16 at 15:19
  • Is this how to do it? ``beaconManager.startMonitoringBeaconsInRegion(new Region(beacon.getId1().toString(), null, null,null))`` – bman Jul 18 '16 at 12:04
  • You'll need to do `beaconManager.startMonitoringBeaconsInRegion(new Region(beacon.getId1().toString(), beacon.getId1(), null,null))` so you only match beacons with the URL you just detected. – davidgyoung Jul 18 '16 at 14:27
  • @davidgyoung I posted another question. Can you check what is wrong with my code? http://stackoverflow.com/questions/38436653/how-to-monitor-eddystone-url-after-ranging-using-android-beacon-library – Aivan Monceller Jul 19 '16 at 12:03
  • @davidgyoung sorry it is now working I was filtering the log and my other log tag is different . Thank you! – Aivan Monceller Jul 19 '16 at 12:08
  • Good to hear, you might close your other question or update the code with what works so other folks aren't confused by it: http://stackoverflow.com/questions/38436653/how-to-monitor-eddystone-url-after-ranging-using-android-beacon-library – davidgyoung Jul 19 '16 at 13:44