后台 iBeacon 检查间隔
Posted
技术标签:
【中文标题】后台 iBeacon 检查间隔【英文标题】:Background iBeacon checking interval 【发布时间】:2014-08-20 07:22:45 【问题描述】:我正在试验 android Beacon 库以使用以下代码在后台监控 iBeacon:
public class IBeaconBootstrap extends Application implements BootstrapNotifier
private RegionBootstrap regionBootstrap;
@Override
public void onCreate()
super.onCreate();
Log.d("IBeaconBootstrap", "App started up");
// wake up the app when any beacon is seen (you can specify specific id
// filers in the parameters below)
Region region = new Region("MyRegion", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
// This is for Apple compatible iBeacons
BeaconManager.getInstanceForApplication(this).getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
@Override
public void didDetermineStateForRegion(int state, Region region)
Log.d("Boostrap didDetermineStateForRegion", "Region " + region.toString());
@Override
public void didEnterRegion(Region region)
Log.d("Boostrap didEnterRegion", "Got a didEnterRegion call");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
@Override
public void didExitRegion(Region region)
Log.d("Boostrap didExitRegion", "Got a didExitRegion call");
当应用启动时,它会每 3/5 分钟检查一次是否存在任何 iBeacon,并将应用置于前台。
其实我需要一个更及时的响应,有什么方法可以静态/动态地改变检查间隔吗?
【问题讨论】:
【参考方案1】:这是完全可配置的代码如下:
// set the duration of the scan to be 1.1 seconds
beaconManager.setBackgroundScanPeriod(1100l);
// set the time between each scan to be 1 minute (60 seconds)
beaconManager.setBackgroundBetweenScanPeriod(60000l);
执行此操作时要小心,因为更频繁的后台扫描会影响电池寿命。见这里:
http://altbeacon.github.io/android-beacon-library/battery_manager.html
【讨论】:
以上是关于后台 iBeacon 检查间隔的主要内容,如果未能解决你的问题,请参考以下文章