EddyStone URL not showing properly on android app?

117 views Asked by At

So I have been learning about beacons recently, I was trying to develop an application that scans beacons around me and get their url, I seem to have a trouble understanding what layout for beacon should I choose, should it be EDDYSTONE_URL, and if so, how should I retrieve this url in android app, here's what I have done:

    public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
    for (Beacon beacon : beacons) {
        if (!rangingMessageRaised && beacon.getServiceUuid() == 0xfeaa) {
            // This is a Eddystone-UID frame
            Identifier namespaceId = beacon.getId1();
            Identifier instanceId = beacon.getId2();
            String url = UrlBeaconUrlCompressor.uncompress(beacon.getId1().toByteArray());
            showAlert(TAG, "I see a beacon transmitting a url: " + url +
                    " approximately " + beacon.getDistance() + " meters away.");


            if (beacon.getExtraDataFields().size() > 0) {
                long telemetryVersion = beacon.getExtraDataFields().get(0);
                long batteryMilliVolts = beacon.getExtraDataFields().get(1);
                long pduCount = beacon.getExtraDataFields().get(3);
                long uptime = beacon.getExtraDataFields().get(4);

                Log.d(TAG, "The above beacon is sending telemetry version " + telemetryVersion +
                        ", has been up for : " + uptime + " seconds" +
                        ", has a battery level of " + batteryMilliVolts + " mV" +
                        ", and has transmitted " + pduCount + " advertisements.");

            }
        }
    }
    rangingMessageRaised=true;
}

Code for setting up beacon layout:

    // Detect the URL frame:


beaconManager.getBeaconParsers().add(new BeaconParser().
             setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
beaconManager.bind(this);

The identifier I used for EDDYSTONE_URL is when creating beacon region is :

try {
    beaconRegion = new
    Region("MyBeacons", null,null,null);
    //I initially wrote this for EDDYSTONE_UID 
    //which seems to work for getting UID 
    // And distance but not url

    //Identifier myBeaconNamespaceId =  
    //Identifier.parse("0x2f234454f4911ba9ffa6");
    // Identifier myBeaconInstanceId
    //Identifier.parse("0x000000000001");
    //  Region region = new Region("my- beacon-region", myBeaconNamespaceId, myBeaconInstanceId, null);
    beaconManager.startMonitoringBeaconsInRegion(beaconRegion);
    beaconManager.startRangingBeaconsInRegion(beaconRegion);
        } catch (RemoteException e) {
        e.printStackTrace();
      }
    }

The output I am getting for the the beacon layout EDDYSTONE_URL is:

"I see a beacon transmitting a url: DT∆ws#2 approximately 0.00969 meters away".

The url seems to be encoded or giving a very weird value, maybe it's the problem with the beacon.getId1() that I am applying url decompressor on.

0

There are 0 answers