I am experimenting the Android Beacon Library to monitoring iBeacon in background with this code:
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");
}
}
The app goes foreground when detects an iBeacon if it is running but nothing happens if the app is not running. Is this the expected behavior or the app is supposed to be started if it is not running?
You probably need to clarify what you mean by "the app is not running". Do you mean:
Using the code above, here is the expected behavior in each case:
It is important to note that when no Activity is visible, the library will only do a scan tyo look for beacons every 5 minutes, so detection can take that long. This interval is fully configurable.
The restrictions on case (3) are imposed by Android OS. An event must occur allowing restart of an app after it is killed by a user.