-->

我怎样才能“刷新”我RegionBootstrap(安卓灯塔库)?(How can I “refre

2019-10-23 01:06发布

我正在开发一款Android应用,用信标(由于Android的灯塔图书馆的使用)的作品。 我有一个扩展BootstrapNotifier调用它创建了一个新的RegionBootstrap控制器(我的班级)方法的应用程序。 一切工作正常时,应用程序启动并与相应地区的灯塔,当他们进入或离开特定区域触发通知。

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);
    ...

}

这是控制器:

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

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

    }

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

现在,我给加地区的可能性,我想立即检测时,信标进入或离开该区域。 要做到这一点,我想我不得不简单地重新调用setRegionBootstrap方法,通过区域的新的列表。 取而代之的是,我没有进入或离开新的地区,除非我重新启动应用程序的通知。 任何想法我怎么能解决这个问题? 谢谢。

Answer 1:

您应该建立一个RegionBootstrap只有一次。 如果你想通过添加新的改变监视区域内,只是这样做的直接BeaconManager是这样的:

beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));


文章来源: How can I “refresh” my RegionBootstrap (Android Beacon Library)?