Search code examples
altbeacon

Filtering Alt beacon with manufacturer identifier and UUID begins with specific format


One of my use case requires to filter all the beacons which is generated by specific manufacturer and UUID starts with specific string.

The ALT beacon library (https://altbeacon.github.io/android-beacon-library/javadoc/reference/org/altbeacon/beacon/Region.html) provides Region class to filter the beacon based on the ID1, ID2, ID3.

I could not find any option to filter all the beacons at the library level which has specific manufacturer ID and the UUID begins with specific characters.

The API documentation with sample code to configure ALT Beacon library for filtering is appreciated and this helps to avoid additional filtering logic implementation at the application.


Solution

  • Filtering on a prefix of the UUID is unusual, but it is possible by defining a custom beacon layout and defining an additional identifier to be the UUID prefix. Because this new extra identifier will be treated as an independent identifier, it won't work like a string prefix -- its default representation will.be a hex string (without dashes).

    If you want to filter on the first five bytes of the UUID for iBeacon, you'd set up a beacon parser like this:

    beaconManager.getBeaconParsers().add(new BeaconParser().
                   setBeaconLayout("m:2-3=0215,i:4-8,i:4-19,i:20-21,i:22-23,p:24-24")); // note the new 5 byte prefix identifier:  i:4-8
    

    Now each beacon will have four identifiers instead of three, the first of which will be the beginning 5 bytes of the UUID, the second the full UUID, the third the major and the fourth the minor.

    You can set up a region to match the first five bytes of this UUID, 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 like this:

    Region region = new Region("prefixRegion", "0x2F234454CF", null, null);

    If you want the prefix to be a different length than 5, simply adjust the i:4-8 part of the layout above to end in a different offset than 8.