我正在尝试检测我的某个通知何时被清除(通过单独滑动或通过“全部删除”通知按钮)。我试图解除AlarmManager警报,但到目前为止,它还没有为我工作。我的代码出了什么问题?
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();
}
}
}
正如你所看到的,我将System.out.println()
投入到我的子类中,以检查我的代码是否甚至达到了该类。我无法在LogCat输出中看到该行,因此我假设由于某种原因,我的PendingIntent.getService()
行无效。我该如何解决这个问题?谢谢! :d