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?
android ibeacon ibeacon-android altbeacon android-ibeacon
Ninja
source share