【问题标题】:android beacon library get state for regionandroid信标库获取区域状态
【发布时间】:2016-07-20 10:30:43
【问题描述】:

BootstrapNotifier(即MonitorNotifier)有进入/退出区域的回调,但是如何在应用启动时获取区域状态(应用如何实现已经在一个区域中)?

【问题讨论】:

    标签: android ibeacon-android android-ibeacon beacon


    【解决方案1】:

    Android Beacon Library 2.8.1 版开始,唯一的方法是访问一些内部库类,如下所示:

    if (MonitoringStatus.getInstanceForApplication(this).stateOf(region) != null && MonitoringStatus.getInstanceForApplication(this).stateOf(region).isInside()) { // Do something }

    我建议不要在生产代码中使用它,因为这个内部 API 可能会发生变化。在库的下一个版本中,将有一种方法可以在 BeaconManager 上获取此信息,如下所示:

    beaconManager.requestStateForRegion(region);
    

    上述方法会导致在 MonitorNotifier 或 BootstrapNotifier 上进行回调:didDetermineStateForRegion(int state, Region region);

    【讨论】:

    • 非常感谢,真的。有用!即使不替换“做某事”部分,也会调用 didDetermineStateForRegion 回调:非常好。测试没问题,我会在投入生产之前等待库的下一个版本;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    相关资源
    最近更新 更多