Search code examples
ibeacon-androideddystone

Is it possible to detect beacons based on partial UUID?


Is it possible to detect beacons based on partial UUID? To detect a beacon with a specific UUID say '08282922101291283379816fdae', we use Identifier.parse('08282922101291283379816fdae'). I am trying to use the first 3 values as a company identifier and would only like to detect company specific beacons. So my question is can we monitor for beacons which starts with a UUID say '007' irrespective of the rest of the UUID?

Any help would be much appreciated, Thanks!


Solution

  • If using the Android Beacon Library, you can do this by defining a custom beacon format that specifies a fourth identifier, which is your UUID prefix. The one trick is that you can only do this by marching one or more bytes, so while you could match a prefix of 0070 or 00, you could not match 007 because it is 1.5 bytes. (You could however set up 16 different regions to match 0070, 0071, 0072,... 007F, which would accomplish the same thing as 007).

    Here is an example with AltBeacon. The same would be possible with other beacon layouts, too:

    beaconManager.getBeaconParsers().clear();
    beaconManager.getBeaconParsers().add(new BeaconParser("AltBeacon with two-byte prefix identifier").setBeaconLayout("m:2-3=beac,i:4-5,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    ...
    Region region = new Region("Any UUID starting with 0070", Identifier.parse("0x0070", 2), null, null);