使用Android Beacon Library在Android 8.1中无法使用快速信标检测功能

时间:2018-03-02 22:17:30

标签: android ibeacon beacon ibeacon-android altbeacon

我正在尝试在Android 8.1下实现David G Young的快速信标检测,如here所示。在这种情况下快速信标检测只是意味着我希望即使应用程序未运行或处于后台也能检测到信标,类似于iOS指定区域后如何检测硬件级别的信标。

而不是从头开始我使用页面上链接的最新信标库。

我的理解是"在背景中启动应用程序" this page上的示例允许设置快速信标检测。虽然我可以做"监控"示例工作(从而确保没有布局问题等),我不能为我的生活做出快速的信标检测工作。事实上,我认为页面上的示例是不正确的,因为它设置了regionBootstrap而没有任何过滤。正如博客页面所解释的那样,Android 8.1需要一个过滤器才能工作。但是,即使添加UUID过滤器(并使用iBeacon布局),它也不会触发:

      A---B---C       develop
     /         \ 
D---E---F---G---M---C' master

同样,使用监控时完全相同,因此它与UUID或布局无关。

设置RegionBootstrap,我确实看到它一次调用didDetermineStateForRegion事件,但之后它已经死了。 我的理解是,如果出现问题,它至少应该启动一个运行扫描的JobScheduler,但这似乎永远不会发生。事实上,看看" adb shell dumpsys jobscheduler"我看到零活跃的工作。

这是我在App类的onCreate()函数中的代码:

regionBootstrap = new RegionBootstrap(this, new Region("BackgroundRegion", Identifier.parse("e1234460-beac-acda-acda-adaaacdadded"), null, null));

以下内容对事件采取行动:

    beaconManager = BeaconManager.getInstanceForApplication(this);
    if (beaconManager.isAnyConsumerBound()) return;

    for (Region region : beaconManager.getMonitoredRegions()) {
        Timber.e("ACTIVELY MONITORED BEACON REGION: " + region.getUniqueId() + " --> STOPPING MONITORING");
        try {
            beaconManager.stopMonitoringBeaconsInRegion(region);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    beaconManager.getBeaconParsers().clear();
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25")); //Kontakt.io iBeacon
    beaconManager.setDebug(true);

    regionBootstrap = new RegionBootstrap(this, new Region("BackgroundRegion", Identifier.parse(beaconUUID), null, null));

和相应的日志(过滤" beacon"):

@Override
public void didEnterRegion(Region region) {
    Timber.e("BACKGROUND BEACON EVENT: ENTERED BOOTSTRAP REGION");
    regionBootstrap.disable();
    Intent intent = new Intent(this, StartupActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    this.startActivity(intent);
}

@Override
public void didExitRegion(Region region) {
    Timber.e("BACKGROUND BEACON EVENT: EXITED BOOTSTRAP REGION");
}

@Override
public void didDetermineStateForRegion(int i, Region region) {
    Timber.e("BACKGROUND BEACON EVENT: SWITCH");
}

我无法肯定地说,但我的直觉是,应该在" AppStarter:等待BeaconService连接"之后发生一些事情。我期待着一个联系。

任何帮助将不胜感激。在Android 8.1的后台快速信标检测/启动的完整工作示例将非常感激!

0 个答案:

没有答案
相关问题