How to detect multiple beacons using Android Android library?

I use the AltBeacon sample application on my Android device - the sample application provided by altbeacon.org is here: https://github.com/AltBeacon/android-beacon-library-reference p>

However, when the application starts, only one beacon is detected and displayed. My Android device has about 5 beacons. How to identify all beacons?

In RangingActivity.java, I noticed this method, which is called when the beacon appears:

public void onBeaconServiceConnect() { beaconManager.setRangeNotifier(new RangeNotifier() { @Override public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) { if (beacons.size() > 0) { EditText editText = (EditText) RangingActivity.this.findViewById(R.id.rangingText); Beacon firstBeacon = beacons.iterator().next(); logToDisplay("The first beacon " + firstBeacon.toString() + " is about " + firstBeacon.getDistance() + " meters away."); } } } 

I changed the iterator to read from the collection in a while loop as follows:

  Beacon firstBeacon; while(beacons.iterator().hasNext()){ firstBeacon = beacons.iterator().next(); logToDisplay("The first beacon " + firstBeacon.toString() + " is about " + firstBeacon.getDistance() + " meters away."); } 

However, the application is disconnected with this modification.

My questions:

(1) How can I display all the beacons that are near my Android device?

(2) How can I detect lighthouses leaving the area?

+7
android ibeacon ibeacon-android altbeacon android-ibeacon
source share
1 answer

For 1. I think you need to use a For loop. Like this.

 for (Beacon beacon : beacons) { logToDisplay("The beacon " + beacon.toString() + " is about " + beacon.getDistance() + " meters away."); } 

For 2. I am having trouble detecting this, but it could be a long timeout. So be very patient. I think that the code in the Monitoring activity can be changed to display a message for this. Or you can view the logarithm from the device. A simple logToDisplay can be used inside the didExitRegion section of the BeaconReferenceApplication application.

 public void didExitRegion(Region region) { if (monitoringActivity != null) { monitoringActivity.logToDisplay("I no longer see a beacon in the "+region.getUniqueId()); } } 
+5
source share

All Articles