android - iBeacons' background ranging with Altbeacon Library -
i need range beacons on background using altbeacons library(work on foreground mode)
on android monitor log never shows message didrangebeaconsinregion method.
on didenterregion, messages displayed correctly.
i tried code below no success, can 1 guide me how it?
public class inbeaconapplication extends application implements bootstrapnotifier, rangenotifier { private beaconmanager beaconmanager; private arraylist<inbeacon> userbeaconarraylist; private inbeaconuser inbeaconuser; @override public void oncreate() { super.oncreate(); log.d("inbeacon", "application created"); //beaconmanager , custom beaconparser layout beaconmanager = beaconmanager.getinstanceforapplication(this); beaconmanager.getbeaconparsers().clear(); beaconmanager.getbeaconparsers().add(new beaconparser() .setbeaconlayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")); beaconmanager.setregionstateperistenceenabled(false); //set beacommanager background between scan periods long period = 1000 * 30; //equal 30 seconds beaconmanager.setbackgroundbetweenscanperiod(period); // wake app when beacon seen region region = new region(utils.region_id, identifier .parse(utils.inbeacon_uuid), null, null); new regionbootstrap(this, region); new backgroundpowersaver(this); } boolean checkpermissionforrange(){ if (build.version.sdk_int >= build.version_codes.m) { return getapplicationcontext().checkselfpermission( manifest.permission.access_fine_location) != packagemanager.permission_granted; } return true; } @override public void didenterregion(region region) { log.d("inbeacon", "didenterregion"); utils.sendnotification(this, "test"); if (checkpermissionforrange()) return; log.d("inbeacon", "permissions ok"); try { beaconmanager.startrangingbeaconsinregion(region); log.d("inbeacon","startranging"); } catch (remoteexception e) { log.e("inbeacon",e.getmessage()); } } @override public void didexitregion(region region) { log.d("inbeacon", "didexitregion"); try { beaconmanager.stoprangingbeaconsinregion(region); } catch (remoteexception e) { e.printstacktrace(); } } @override public void didrangebeaconsinregion(collection<beacon> collection, region region) { log.d("inbeacon", "didrangebeaconsinregion"); arraylist<beacon> newbeacons = new arraylist<>(collection); .............code need beacons..... }
it looks code needs call:
beaconmanager.setrangenotifier(this);
Comments
Post a Comment