setBackgroundBetweenScanPeriod()未生效

时间:2015-12-07 07:26:01

标签: android beacon eddystone

我试图在后台每30秒检测beacon一次,当应用程序在前台时,它应该不间断地检测信标。为此,这是我写的代码,

public void onCreate() {
    super.onCreate();
    mBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
    mBeaconManager.getBeaconParsers().clear();
    mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
    Identifier myBeaconNamespaceId = Identifier.parse("0xe2bfcc3cc2370789caef");
    Region region = new Region("my-beacon-region", myBeaconNamespaceId, null, null);

    mBeaconManager.setBackgroundBetweenScanPeriod(25000l);
    mBeaconManager.setBackgroundScanPeriod(5000l);
    mBeaconManager.setForegroundScanPeriod(60000l);
    mBeaconManager.setForegroundBetweenScanPeriod(0l);

    try {
        mBeaconManager.updateScanPeriods();
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    regionBootstrap = new RegionBootstrap(this, region);
    backgroundPowerSaver = new BackgroundPowerSaver(this);

}

即使我设置了特定的扫描周期,它仍然会以默认的时间间隔检测信标。感谢。

1 个答案:

答案 0 :(得分:0)

了解将前景扫描间隔设置为:

mBeaconManager.setForegroundScanPeriod(60000l);

不会不断提供结果。它将扫描60秒,然后仅在该间隔结束时传送结果。

此外,对updateScanInterval的调用将始终抛出异常,因为该服务尚未绑定。这应该没问题,因为代码预先设置了新的扫描间隔,因此当服务绑定发生时,扫描间隔将生效。