androidaltbeaconeddystoneeddystone-url

How to transmit an Eddystone Beacon with Url using Altbeacon Library for Android


I am able to run the examples mentioned on the Github site of the Altbeacon library for Android for transmitting an Altbeacon. This works perfectly on my phone wherein I am able to transmit an Altbeacon and detect it via another phone.

I need to develop a POC wherein I can transmit an Eddystone Beacon too along with Url data. I am a bit confused as to how I can set the Url data while building the Beacon using the Builder, the docs on the site of Altbeacon library demonstrate the scanning part of Eddystone beacons but transmitting an Eddystone beacon with Url is what is missing over there.

If someone can point be to the right direction it would be helpful.


Solution

  • Try something like this:

        try {
            byte[] urlBytes = UrlBeaconUrlCompressor.compress("http://www.davidgyoungtech.com");
            Identifier encodedUrlIdentifier = Identifier.fromBytes(urlBytes, 0, urlBytes.length, false);
            ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
            identifiers.add(encodedUrlIdentifier);
            beacon = new Beacon.Builder()
                    .setIdentifiers(identifiers)
                    .setManufacturer(0x0118)
                    .setTxPower(-59)
                    .build();
            BeaconParser beaconParser = new BeaconParser()
                    .setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT);
            BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
            beaconTransmitter.startAdvertising(beacon);
        } catch (MalformedURLException e) {
            Log.d(TAG, "That URL cannot be parsed");
        }