Hi i have created app using altbeacon reference app. And i want to call didEnterRegion using bootstrap notifier when app sees beacon in background. But i dont want it to scan background every 5 minutes, i want my app react to new beacon immediately. Is there some way to do this ?
My Code :
private static final String TAG = ".Application";
private final Identifier uuid = Identifier.parse("A1B2C3D4-AAAA-48D2-B060-D0C0D0C0D0C0");
private RegionBootstrap regionBootstrap;
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App has started");
Region region = new Region(TAG, uuid, null, null);
BeaconManager.debug = true;
BeaconManager.getInstanceForApplication(this).getBeaconParsers().add(
new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void didEnterRegion(Region region)
{
Log.i(TAG, "BACKGROUND ACTIVATED");
}
@Override
public void didExitRegion(Region region) {
}
@Override
public void didDetermineStateForRegion(int i, Region region) {
}
}
You can increase the frequency of background scans with the following code:
beaconManager.setBackgroundBetweenScanPeriod(0l);
beaconManager.setBackgroundScasnPeriod(1100l);
This will make the background detection times as fast as in the foreground. But be forewarned, this will make your app use lots of battery power. You can tweak the between scan period to your tolerance for battery drain. As you noted, the default is 5 minutes (5*3600l).
Android L has new scanning APIs which promise to help improve this tradeoff between detection timers and battery usage. But for4.3 and 4.4 apps, you need to make a judgment call.
来源:https://stackoverflow.com/questions/25973006/altbeacon-library-bootstrapnotifier-does-not-call-didenterregion