Hi guys, just got your Estimote beacons yesterday so new to the club.
I cant get the monitoring to work in the background. When the app is open it works perfectly. It triggers the onEntered event and the onExited event as it should. When I press the home button it no longer works. Logcat still gives me the startLEscan and stopLEscan but it can no longer trigger the onEntered event. After a little while it still triggers the onExited event though.
Any idea what’s going wrong? Im using a nexus 5 with android 6.0 atm.
Thanks in advance, here’s my application code.
public class MyApplication extends Application {
private BeaconManager beaconManager;
@Override
public void onCreate() {
super.onCreate();
beaconManager = new BeaconManager(getApplicationContext());
beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
@Override
public void onEnteredRegion(Region region, List<Beacon> list) {
showNotification(
"Your gate closes in 47 minutes.",
"Current security wait time is 15 minutes, "
+ "and it's a 5 minute walk from security to the gate. "
+ "Looks like you've got plenty of time!");
}
@Override
public void onExitedRegion(Region region) {
showNotification(
"Leaving gate","Goodbye"
);
}
});
beaconManager.setBackgroundScanPeriod(1000,1000);
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startMonitoring(new Region("monitored region",
UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null));
}
});
}
public void showNotification(String title, String message) {
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivities(this, 0,
new Intent[]{notifyIntent}, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
notification.defaults |= Notification.DEFAULT_SOUND;
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notification);
}
}