Search code examples
ibeacon-androidaltbeaconeddystone

Can range monitoring be done in the background?


Based on the samples provided in the site http://altbeacon.github.io/android-beacon-library/samples.html , we can use RegionBootstrap to perform background monitoring of regions.

Instead of launching an app, once a region is entered, I start ranging by binding the Application class as a consumer. However, after calling BeaconManager.bind, onBeaconServiceConnect() is not called.

Is this a limitation of the library or is there something I'm doing wrong for ranging?


Solution

  • When using the RegionBootstrap class, you don't need to make your Application class implement the BeaconConsumer interface, as the RegionBootstrap implementation handles that internally. You simply make the Application class implement BootstrapNotifier.

    You can see an example of this in the samples page you mention under the Starting an App in the Background section. Note that the example in that section does not explicitly call the bind method on BeaconManager, nor does the Application class implement BeaconConsumer.

    EDIT: If you want to add background ranging, simply make the Application class implement RangeNotifier, then add the following to the didEnterRegion method:

    beaconManager.setRangeNotifier(this);
    try {
        beaconManager.startRangingBeaconsInRegion(region);
    } catch (RemoteException e) {    }