I am creating an app to add and remove proximity alerts.
Proximity alert working fine. It does notifies me when I come close to the coordinates. But I can not remove them when I don't want them. Here is the code I've used to Add and remove proximity alerts
.
When I stop and read them the number of alerts increments by one than the previous count.
Adding Proximity Alerts
private void add_lert() {
locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
String proximitys="com.realtech.proxtest";
Intent i=new Intent(proximitys);
pi = PendingIntent.getBroadcast(MainActivity.this, 11, i, PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(lat, lng, radius, -1, pi);
IntentFilter filter=new IntentFilter(proximitys);
registerReceiver(new ProxReceiver(),filter);
}
Removing Alerts
private void remove_alert() {
LocationManager locationManager1=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
String proximitys="com.realtech.proxtest";
Intent i=new Intent(proximitys);
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 11, i, PendingIntent.FLAG_CANCEL_CURRENT);
locationManager1.removeProximityAlert(pi);
}