2

次のコードを使用して、バックグラウンドで iBeacon を監視する Android ビーコン ライブラリを実験しています。

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");
}
}

アプリが開始されると、iBeacon が周囲にあるかどうかを 3/5 分ごとにチェックし、アプリをフォアグラウンドにします。

実際にはもっと迅速な対応が必要です。チェック間隔を静的/動的に変更する方法はありますか?

4

1 に答える 1