我试图beacon
在后台每 30 秒检测一次,当应用程序在前台时,它应该不断检测信标,没有任何间隔。为此,这是我编写的代码,
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);
}
即使我设置了特定的扫描周期,它仍然会以默认的时间间隔检测信标。谢谢。