I have to compare 2 PendingIntent for delete proximityAlert before create another, because it seems not work. I have in my function:
SharedPreferences pref = getSharedPreferences("proximityService", Context.MODE_PRIVATE);
int unique_id = pref.getInt("PENDING_UNIQUEID",0);
removeProximityAlert(unique_id);
int requestId = (int) System.currentTimeMillis();
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("PENDING_UNIQUEID", requestId);
editor.commit();
PendingIntent proximityIntent = PendingIntent.getBroadcast(getApplicationContext(), requestId, intentNew, 0);
and remove function
public void removeProximityAlert(int unique_id) {
String context = Context.LOCATION_SERVICE;
LocationManager locationManager = (LocationManager) getSystemService(context);
Intent anIntent = new Intent(PROX_ALERT_INTENT);
PendingIntent operation =
PendingIntent.getBroadcast(getApplicationContext(), unique_id, anIntent, 0);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.e("error", "permission");
return;
}
locationManager.removeProximityAlert(operation);
if (mHandleMessageReceiver != null){
unregisterReceiver(mHandleMessageReceiver);
}
}
So, the proximity isn't deleted and my broacast continue to receive even last proximity, I think the problem is the different pendingIntent, but I don't understand if it is the problem, so I would know if I can compare 2 pending intent.