I use the Android Beacon Library to scan Eddystone beacons with my phone. The application is properly running in the foreground.
Now, I want to detect Eddytone beacons in the background mode, but the example in the website of the library doesn't run on my application.
In my case, I have an activity for the UI and a separate Service for the foreground beacons detection.
I have exactly the same code of the example and the launchMode of my activity is "singleInstance".
Here is my code:
public class Background extends Application implements BootstrapNotifier{
private static final String TAG = "Background";
private RegionBootstrap regionBootstrap;
@Override
public void onCreate() {
super.onCreate();
Log.e(TAG, "App started up");
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
beaconManager.setBackgroundScanPeriod(1100L);
beaconManager.setBackgroundBetweenScanPeriod(5000);
Region region = new Region("all", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// Don't care
}
@Override
public void didEnterRegion(Region arg0) {
Log.e(TAG, "Got a didEnterRegion call");
regionBootstrap.disable();
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
@Override
public void didExitRegion(Region arg0) {
// Don't care
}
}
Am I missing anything? Or due to my separate service, this is not the proper method?
Thank you for your help.