AltBeacon库BootstrapNotifier不调用didEnterRegion [英] AltBeacon library BootstrapNotifier does not call didEnterRegion

查看:88
本文介绍了AltBeacon库BootstrapNotifier不调用didEnterRegion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用altbeacon参考应用创建了应用。我想在应用程序在后台看到信标时使用引导程序通知程序调用didEnterRegion。但是我不希望它每5分钟扫描一次背景,我希望我的应用立即对新的信标做出反应。有什么方法可以做到这一点?

Hi i have created app using altbeacon reference app. And i want to call didEnterRegion using bootstrap notifier when app sees beacon in background. But i dont want it to scan background every 5 minutes, i want my app react to new beacon immediately. Is there some way to do this ?

我的代码:

private static final String TAG = ".Application";
private final Identifier uuid = Identifier.parse("A1B2C3D4-AAAA-48D2-B060-D0C0D0C0D0C0");
private RegionBootstrap regionBootstrap;

@Override
public void onCreate() {
    super.onCreate();

    Log.d(TAG, "App has started");

    Region region = new Region(TAG, uuid, null, null);
    BeaconManager.debug = true;
    BeaconManager.getInstanceForApplication(this).getBeaconParsers().add(
            new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
    regionBootstrap = new RegionBootstrap(this, region);
}

@Override
public void didEnterRegion(Region region)
{
    Log.i(TAG, "BACKGROUND ACTIVATED");
}

@Override
public void didExitRegion(Region region) {

}

@Override
public void didDetermineStateForRegion(int i, Region region) {

}

}

推荐答案

您可以使用以下代码提高后台扫描的频率:

You can increase the frequency of background scans with the following code:

beaconManager.setBackgroundBetweenScanPeriod(0l);
beaconManager.setBackgroundScasnPeriod(1100l);

这将使背景检测时间与前景一样快。但是请注意,这将使您的应用消耗大量电池电量。您可以调整两次扫描之间的时间,以达到电池耗电的容限。如您所述,默认值为5分钟(5 * 3600l)。

This will make the background detection times as fast as in the foreground. But be forewarned, this will make your app use lots of battery power. You can tweak the between scan period to your tolerance for battery drain. As you noted, the default is 5 minutes (5*3600l).

Android L具有新的扫描API,这些API有望帮助改善检测计时器和电池使用量之间的权衡。但是对于4.3和4.4应用程序,您需要做出判断。

Android L has new scanning APIs which promise to help improve this tradeoff between detection timers and battery usage. But for4.3 and 4.4 apps, you need to make a judgment call.

这篇关于AltBeacon库BootstrapNotifier不调用didEnterRegion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆