AltBeacon library BootstrapNotifier does not call didEnterRegion

ⅰ亾dé卋堺 提交于 2019-12-22 09:20:57

问题


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) {

}

}


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!