Reputation: 14053
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.
Upvotes: 1
Views: 328
Reputation: 64941
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.
Upvotes: 1
Reputation: 677
One solution would be to pull out all of the dashes from both, and convert them both to upper case and compare them.
Fix your current uuid to upper with no dashes (this uses System.Linq
):
uuid = new string(uuid.Where(c => c != '-').ToArray()).ToUpper();
This will change your uuid from:
e2c56db5-dffb-48d2-b060-d0f5a71096e0
To:
E2C56DB5DFFB48D2B060D0F5A71096E0
Upvotes: 2