AltBeacon BootstrapNotifier library does not call didEnterRegion

Hi I have created an app using altbeacon reference app. And I want to call didEnterRegion using bootstrap notification when app sees a beacon in the background. But I don't want it to scan the background every 5 minutes, I want the app to respond immediately to a new beacon. Is there a 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) {

}

      

}

+3


source to share


1 answer


You can increase the frequency of background scans with the following code:

beaconManager.setBackgroundBetweenScanPeriod(0l);
beaconManager.setBackgroundScasnPeriod(1100l);

      



This will make the background detection time as fast as the foreground. But be warned, this will force your app to use more battery power. You can adjust the interval between scan periods up to your battery drain tolerance. As you noted, the default is 5 minutes (5 * 3600).

Android L has new scanning APIs that promise to help improve this tradeoff between detection timers and battery usage. But for 4.3 and 4.4 apps, you need to make a legal challenge.

+2


source







All Articles