Skip to content Skip to sidebar Skip to footer

How To Detect Region Enter/exit For Multiple Beacons Using Altbeacon Android-beacon-library?

I am working with iBeacons and using the AltBeacon library. beaconManager.getBeaconParsers() .add(new BeaconParser() .setBeaconLayout('m:2-3=0215,i:4-19,i

Solution 1:

Two options:

  1. Set up a different region to match only each individual beacon, specifying all their identifiers, and monitor for each. You will get a different entry and exit callback for each region.

    Regionregion1=newRegion("myIdentifier1", Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), Identifier.parse("1"), Identifier.parse("1"));        
    Regionregion2=newRegion("myIdentifier2", Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), Identifier.parse("1"), Identifier.parse("2"));   
    
    beaconManager.startMonitoringBeaconsInRegion(region1);
    beaconManager.startMonitoringBeaconsInRegion(region2);    
    
  2. Enable ranging, and put code in the didRangeBeaconsInRegion callback to track individual beacons. You can use a java.util.HashMap to keep track of all beacons that are visible (with a timestamp for the latest time each was seen), and then if you haven't seen a beacon in, say, five seconds, you can remove the beacon from the HashMap and execute your exit logic for that beacon.

Option 1 is great for a small number of beacons where you know their identifiers up front. Option 2 is more involved, but better for a large number of beacons or if you do not know their identifiers in advance.

Solution 2:

/***************This Code for estimote Beacons *****************/

privatefinalRegionALL_ESTIMOTE_BEACONS_REGION=newRegion("beaconall", null, null, null);

private BeaconManager beaconManager;

publiconCreate()
{

    beaconManager.connect(newBeaconManager.ServiceReadyCallback()
    {
        @OverridepublicvoidonServiceReady()
        {
            Log.d("Lalit", "Beacon service Ready");

            beaconManager.startRanging(ALL_ESTIMOTE_BEACONS_REGION);
            beaconManager.startMonitoring(ALL_ESTIMOTE_BEACONS_REGION);
        }
    });
    beaconManager.setRangingListener(newBeaconManager.RangingListener() {
        @OverridepublicvoidonBeaconsDiscovered(Region region, final List<Beacon> beacons) {

            intindex= beacons.size();
            // UUID uuid = UUID.fromString("");if (beacons.size() > 0) {
                BeaconSelectedBeacon= beacons.get(index-1);

                Log.d("Lalit", "Beacon Id :- " + SelectedBeacon.getProximityUUID());
                Log.d("Lalit", "Beacon major :- " + SelectedBeacon.getMajor());
                Log.d("Lalit", "Beacon miner :- " + SelectedBeacon.getMinor());
                Log.d("Lalit", "Beacon total :- " + beacons.size());
                Log.d("Lalit","Distance :- "+ getDistance(SelectedBeacon.getRssi(),SelectedBeacon.getMeasuredPower()));
            }

        }
    });

    beaconManager.setMonitoringListener(newBeaconManager.MonitoringListener() {
        @OverridepublicvoidonEnteredRegion(Region region, List<Beacon> list) {
            Calendarcalendar= Calendar.getInstance();
            Dateentertime= calendar.getTime();
            Log.d("Lalit", "Region Enter :- " + entertime);
            Log.d("List", "Region  UUID id :- " + region.getProximityUUID());
        }

        @OverridepublicvoidonExitedRegion(Region region) {
            Calendarcalendar= Calendar.getInstance();
            Dateentertime= calendar.getTime();
            Log.d("Lalit", "Region exit :- " + entertime);
            Log.d("List", "Region  UUID id :- " + region.getProximityUUID());
        }
    });
}

Post a Comment for "How To Detect Region Enter/exit For Multiple Beacons Using Altbeacon Android-beacon-library?"