How can I “refresh” my RegionBootstrap (Android Be

2019-08-03 16:38发布

I am developing an Android app that works with Beacons (thanks to the usage of Android Beacon Library). I have an Application that extends BootstrapNotifier that calls a Controller (my class) method which creates a new RegionBootstrap. Everything works fine when the app starts and the Beacons related to the corresponding Regions triggers notifications when they enter or leave that specific Region.

public class BackgroundApplication extends Application implements BootstrapNotifier, RangeNotifier {
...
@Override 
public void onCreate() {

    this.controller = Controller.getInstance();

    mAllBeaconsRegion = new Region("all beacons", null, null, null);

    //the following call returns the correct list of regions
    this.regionList = this.controller.getRegionList(this);  

    this.regionList.add(mAllBeaconsRegion);

    this.controller.setBootstrapNotifier(this);
    this.controller.setRegionBootstrap(this.regionList);
    ...

}

This is the Controller:

public class Controller {
...
    public void setRegionBootstrap(ArrayList<Region> regionList){

        this.regionBootstrap = new RegionBootstrap(this.bootstrapNotifier, regionList);

    }

    public void setBootstrapNotifier (BootstrapNotifier bn){
        this.bootstrapNotifier = bn;
    }
}

Now, I give the possibility to add Regions, and I would like to immediately detect when a Beacon enters or leaves that Region. To do so, I thought I had to simply re-call that setRegionBootstrap method, passing the new list of Regions. Instead, I have no notifications of entering or leaving the new Region unless I restart the app. Any idea of how I can fix this? Thanks.

1条回答
萌系小妹纸
2楼-- · 2019-08-03 17:03

You should construct a RegionBootstrap only once. If you want to alter the monitored regions by adding new ones, just do so directly on BeaconManager like this:

beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
查看更多
登录 后发表回答