Android deleteIntent not working? What happened to my code?

I am trying to detect when one of my notifications is cleared (either by debugging it separately, or using the "delete all" button). I am trying to turn off the AlarmManager, but so far it has not worked for me. What is wrong with my code?

onCreate(Bundle savedInstanceState) { ... NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notif = new Notification(R.drawable.flag_red_large, reminderName, System.currentTimeMillis()); notif.deleteIntent = PendingIntent.getService(this, notifID, new Intent(this, CleanUpIntent.class), 0); //Destroy the activity/notification. finish(); } class CleanUpIntent extends IntentService { public CleanUpIntent() { super("CleanUpIntent"); } @Override protected void onHandleIntent(Intent arg0) { System.out.println(">>>>>>>>>>>>>>>>>>>" + "Repeating Alarm Cancelled..."); Intent i = new Intent("com.utilityapps.YouForgotWhat.DisplayReminderNotification"); int reminderID = i.getExtras().getInt("reminderID"); PendingIntent displayIntent = PendingIntent.getBroadcast(this, reminderID, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(displayIntent); displayIntent.cancel(); } } } 

As you can see, I injected System.out.println() into my subclass to check if my code even reaches this class. I do not see this line in my LogCat output, so I assume that for some reason my PendingIntent.getService() not working. How to fix this problem? Thank you !: D

+1
source share

Source: https://habr.com/ru/post/972278/


All Articles