Each lighthouse has an ID .
ID is 20 bytes long and is divided into three parts:
proximityUUID (16 bytes)
major number (2 bytes)
minor number (2 bytes).
How to use them to identify a particular beacon?
First, you should know that there may be many lighthouses around you. These beacons may come from other suppliers, companies, or developers, so you want to filter them out.
To filter beacons, you must use proximityUUID to group beacons provided by you or your company. Give the same proximityUUID all your beacons.
After that, you can start monitoring and vary:
private final Region MY_BEACONS = new Region("MY_BEACONS","YOUR_PROXIMITY_UUID", null, null); beaconManager.startMonitoring(MY_BEACONS); beaconManager.startRanging(MY_BEACONS);
Now, at your listeners, you will be notified when your lighthouses are in the area.
Now suppose you are writing a movie theater app in a city. Each cinema has two different beacons to perform different actions. How to distinguish between cinema beacons and how to do it for a specific beacon in speculative cinema?
Use the major and minor fields. For example:
- use
major to identify all beacons in a particular movie theater, - use
minor to identify a particular beacon in a particular movie theater.
When you create an ID for beacons this way, you can get a specific beacon and complete the action:
private final int SCARY_CINEMA_ID = 1111; private final int SCARY_CINEMA_BEACON_1 = 1; private final int SCARY_CINEMA_BEACON_2 = 2; private final int COMEDY_CINEMA_ID = 2222; private final int COMEDY_CINEMA_BEACON_1 = 1; private final int COMEDY_CINEMA_BEACON_2 = 2; @Override public void onEnteredRegion(Region region, List<Beacon> beacons) { for(Beacon beacon : beacons){ if(beacon.getMajor() == SCARY_CINEMA_ID){ if(beacon.getMinor == SCARY_CINEMA_BEACON_1){
Hope this helps you :)
mklimek
source share