AltBeacon's Android Beacon Library getting major, minor and UUID -
the first thing is first time using beacons. i'm using library altbeacon
currently have several things working, example, when enter region or when leave .. distance beacon correctly. works perfectly. uuid, major , minor .. not know if i'm doing correctly.
this code:
public class hello extends activity implements beaconconsumer { protected static final string tag = "readme"; private beaconmanager beaconmanager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.hola); beaconmanager = beaconmanager.getinstanceforapplication(this); beaconmanager.getbeaconparsers().add(new beaconparser(). setbeaconlayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24")); beaconmanager.bind(this); } @override public void onbeaconserviceconnect() { try { beaconmanager.startrangingbeaconsinregion(new region("myranginguniqueid", identifier.parse("my_uuid"), identifier.parse("1"), null)); } catch (remoteexception e) { } beaconmanager.setrangenotifier(new rangenotifier() { @override public void didrangebeaconsinregion(collection<beacon> beacons, region region) { if (beacons.size() > 0) { log.i(tag, "the first beacon see " + beacons.iterator().next().getdistance() + " meters away."); log.i(tag, "reading…"+"\n"+"proximityuuid:"+" "+ beacons.iterator().next().getid1()+"\n"+ "major:"+" "+beacons.iterator().next().getid2()+"\n"+ "minor:"+" "+beacons.iterator().next().getid3());} } }); beaconmanager.setmonitornotifier(new monitornotifier() { @override public void didenterregion(region region) { log.i(tag, "i saw beacon first time!"); } @override public void didexitregion(region region) { log.i(tag, "i no longer see beacon"); } @override public void diddeterminestateforregion(int state, region region) { log.i(tag, "i have switched seeing/not seeing beacons: " + state); } }); try { beaconmanager.startmonitoringbeaconsinregion(new region("mymonitoringuniqueid", null, null, null)); } catch (remoteexception e) { } } @override protected void ondestroy() { super.ondestroy(); beaconmanager.unbind(this); } }
as said, uuid, major , minor, using
beaconmanager.setrangenotifier (new rangenotifier () {...
setrangenotifier
distance beacon, automatically updated every few seconds, reason, each time updated again uuid, major , minor ..
is right place uuid, major , minor? tried when enter region:
@override public void didenterregion(region region) { log.i(tag, "i saw beacon first time!"); }
…but without success.
i searched lot of information, can not find specific. intention have variable contains uuid, contains major , other containing minor. that's right?
if not right way, is? correct now?
i appreciate , put mention of @davidgyoung …i hope not bother.
greetings.
yes, using rangenotifier
read beacon identifiers correct approach.
the reason cannot identifiers in callback monitornotifier
because callback passes region object region entered/exited. region can contain wildcards of identifiers, won't tell beacons encountered. use cases, not necessary.
the bottom line if want read identifiers doing correct thing using ranging apis , rangenotifier
.
Comments
Post a Comment