Android deleteIntent not working? What's wrong with my code?

末鹿安然 提交于 2019-12-11 07:57:47

问题


I'm trying to detect when one of my notifications is cleared (either by swiping it away individually, or through the "delete all" notifications button). I'm trying to dismiss an AlarmManager alarm, but so far, it hasn't been working for me. What's 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 threw in a System.out.println() into my sub-class to check to see if my code is even reaching that class. I can't see that line in my LogCat output, so I'm assuming that for some reason, my PendingIntent.getService() line isn't working. How do I fix this issue? Thanks! :D

来源:https://stackoverflow.com/questions/12665745/android-deleteintent-not-working-whats-wrong-with-my-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!