0

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.

LorenzoBerti
  • 6,704
  • 8
  • 47
  • 89
  • Post the code that shows how you create `intentNew` and what you put in there. – David Wasser Sep 08 '16 at 05:53
  • I have fixed add to `intentNew` and `anIntent` actions the `unique_id` so `Intent anIntent = new Intent(PROX_ALERT_INTENT+unique_id);` and seems work! – LorenzoBerti Sep 08 '16 at 07:27
  • Good for you! Please answer your own question and accept the answer. This will help others who have a similar problem and get this question off the unanswered questions list. – David Wasser Sep 08 '16 at 08:27

0 Answers0