When monitoring for beacons transmitting Eddystone-UID, regions should be set up like this:
Identifier eddystoneNamespaceId1 = Identifier.parse("0x00000000000000000001");
Identifier eddystoneNamespaceId2 = Identifier.parse("0x00000000000000000002");
Region eddystoneUidRegion1 = new Region("eddystoneUidRegion1",
eddystoneNamespaceId1, null, null);
Region eddystoneUidRegion2 = new Region("eddystoneUidRegion1",
eddystoneNamespaceId2, null, null);
beaconManager.setRangeNotifier(this);
beaconManager.startMonitoringBeaconsInRegion(eddystoneUidRegion1);
beaconManager.startMonitoringBeaconsInRegion(eddystoneUidRegion2);
In this example, two different regions are defined, each with a 10-byte different Eddystone-UID namespace identifier, and a null Eddystone-UID instance identifier so it will match all beacons with those namespace. The last parameter passed to the Region
constructor is also null, because Eddystone-UID beacons only have two identifiers. The code starts monitoring for each of these regions in the last two lines.
The first time any beacon matching the first region is detected (e.g. one with the first namespace identifier), the didEnterRegion
callback will be fired, passing a reference to the eddystoneUidRegion1 object. The equivalent callback will also happen if any beacon matching the second region is detected. You can tell which one is detected by examining the contents of the Region
object passed to the callback. A different callback exists for didExitRegion
when all beacons matching a monitored region disappear.
This is how the Monitoring APIs work. There are also Ranging APIs that give you a callback at approximately 1Hz with a list of all visible beacons that match the Region
. Whether you use the Monitoring APIs or Ranging APIs depends on your use case.