1

我正在尝试检测我的一个通知何时被清除(通过单独滑动它,或通过“删除所有”通知按钮)。我正在尝试解除 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

4

0 回答 0