I would like to have push notifications when my app is open but is in background. For now I have changed the Estimote Demo, and my app gives me a notification when my app is
You should hold BeaconManager
in your application class not in the activity.
Activity will be stopped, destroyed and BeaconManager
will stop monitoring. Application on the other hand will still hold reference and will continue to monitor.
When a beacon is being found while monitoring your application class can post a notification. It trigger some activity when user decides to tap on it.
You should create service.
In your code you should do some changes.
After
beaconManager = new BeaconManager(this);
you should start "beacon service"
if (!beaconManager.isBluetoothEnabled()) {
stopSelf();
}
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
try {
beaconManager.startRanging(ALL_ESTIMOTE_BEACONS_REGION);
} catch (RemoteException e) {
Log.e("error", "Cannot start ranging", e);
}
}
});
Also check if Bluetooth is active on you device.
In procedure beaconManager.setMonitoringListener(new MonitoringListener() add commands to create Notifications.