java - How to get visible beacons from the RegionBootstrap AltBeacon method -


i'm using example code on page (http://altbeacon.github.io/android-beacon-library/samples.html) in starting app in background section , i've got working app.

it detects whenever beacon in range on background.

the problem need know beacon (uuid, major, minor) match against local database , throw notification app still on background.

the didenterregion(region region) function has matchesbeacon method, , i've tried doing following identify of beacons being seen it's throwing nullpointerexception:

public class sightseeing extends activity implements bootstrapnotifier, rangenotifier {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      region region = new region("sightregion", null, null, null);     regionbootstrap = new regionbootstrap(this, region);      beaconmanager.getinstanceforapplication(this).getbeaconparsers().add(             new beaconparser(). setbeaconlayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")     );      beaconmanager.getinstanceforapplication(this).setrangenotifier(this);  }  @override public void didenterregion(region region) {      regionbootstrap.disable();      beaconmanager.getinstanceforapplication(this).setrangenotifier(this);      try {         beaconmanager.getinstanceforapplication(this).startrangingbeaconsinregion(region);     }     catch (remoteexception e) {         log.e(tag, "can't start ranging");     }   }   @override public void didrangebeaconsinregion(collection<beacon> beacons, region region) {     if (beacons.size() > 0) {         iterator<beacon> beaconiterator = beacons.iterator();         while (beaconiterator.hasnext()) {             beacon beacon = beaconiterator.next();             //check if beacon exists in our db , throw notification         }     } } 

am missing obvious or isn't possible library?

edit:

i've updated code sample give guys broader idea , i've tried implementing suggestion foliveira without success.

edit2:

updated code reflect davidgyoung's suggestion. still no luck. have log.d() right on first line of didrangebeaconsinregion() function , isn't being called.

i've tried adding beaconmanager.getinstanceforapplication(this).setrangenotifier(this); before try/catch block , result same.

did implement suggestion wrong or there other way working?

if want app launch on beacon detection, regionbootstrap easiest way go. in order combine ranging needed detect individual beacons, add code in didenterregion method this:

try {     beaconmanager.getinstanceforapplication(this).startrangingbeaconsinregion(region); }  catch (remoteexception e) {      log.e(tag, "can't start ranging"); } 

then implement ranging callback have.

you need remove code below, causing nullpointerexception, because :

for(int i=0; i< beaconslist.size(); i++) {     beacon b = new beacon.builder()             .setid1(beaconslist.get(i).get("uuid"))             .setid2(beaconslist.get(i).get("major"))             .setid3(beaconslist.get(i).get("minor"))             .build();      if(region.matchesbeacon(b)) {         //get info db , throw notification     }  } 

edit: have updated library's reference application show how can done successfully. see here: https://github.com/altbeacon/android-beacon-library-reference/blob/master/src/org/altbeacon/beaconreference/beaconreferenceapplication.java


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -