Search code examples
androidbluetoothibeacon-androidaltbeaconandroid-ibeacon

Beacon UUID is different while scanning


I am trying to find out the UUID of the beacon using altbeacon and the beacon getting detected using below code,

beaconManager.setRangeNotifier(new RangeNotifier() { @Override

public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
    if (beacons.size() > 0) {
        for (Beacon beacon : beacons) {   

        String uuid = beacon.getId1().toString();
        ...
}

But the problem is my actual beacon UUID is

E2C56DB5-DFFB48D2-B060D0F5-A71096E0

Where as the above code giving me the uuid

e2c56db5-dffb-48d2-b060-d0f5a71096e0

Basically both are same except the - symbol position is different on both UUID, this creating some problem on my application

What could be the issue?

Edit:

I can post more code if required.


Solution

  • The UUID format returned by the Android Beacon Library is standard, and the one in the database is not. Since you cannot change the database format easily, you can convert the string format with these lines of java code:

    String uuid = beacon.getId1().toString();
    String s2 = s.replaceAll("-", "").toUpperCase();
    String alternateFormatUuid = s2.substring(0,8)+"-"+s2.substring(8,16)+"-"+s2.substring(16,24)+"-"+s2.substring(24,32);
    

    I'm sure there are more elegant ways to do this, but the above code will do the job.