Search code examples
androidibeacon-androidaltbeaconandroid-ibeacon

How to get url from Eddystone Beacon on monitoring mode using Android Beacon Library?


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?


Solution

  • 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.