I have a problem with proximity alert. I have settings in an Android app where users can turn off / turn on proximity alerts in some places. When they turn off the proximity alert, everything works fine and they wonβt be notified, but if they are turned off and activate the proximity alert again, it will add again and they will receive a notification twice when they reach the location and so on. Therefore, every time they re-activate it, it creates a new proximity alert.
This is the code I use to remove the proximity warning:
private void removeProximityAlert(int id) { final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE ); Intent intent = new Intent(PROX_ALERT_INTENT + id); PendingIntent proximityIntent = PendingIntent.getBroadcast(this, id, intent, PendingIntent.FLAG_CANCEL_CURRENT); manager.removeProximityAlert(proximityIntent); }
And this is the code that I use to add proximity warning:
private void addProximityAlert(double latitude, double longitude, int id, int radius, String title) { final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE ); Intent intent = new Intent(PROX_ALERT_INTENT + id); PendingIntent proximityIntent = PendingIntent.getBroadcast(this, id, intent, PendingIntent.FLAG_CANCEL_CURRENT); manager.addProximityAlert( latitude, longitude, radius, -1, proximityIntent ); IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT + id); registerReceiver(new ProximityIntentReceiver(id, title), filter); }
source share