我正在尝试检测我的通知何时被清除。我的问题直接指的是这个答案,它概述了我应该做什么。这就是我执行这些操作的方式:
// usual Notification initialization here
notification.deleteIntent = PendingIntent.getService(context, 0, new Intent(context, CleanUpIntent.class), 0);
notificationManager.notify(123, notification)
这是 CleanUpIntent 类:
class CleanUpIntent extends IntentService {
public CleanUpIntent() {
super("CleanUpIntent");
}
@Override
protected void onHandleIntent(Intent arg0) {
// clean up code
}
}
之后,我像往常一样简单地启动通知,但是当我去测试它时(按“清除所有通知”),什么也没有发生。我插入了一行代码,在 IntentService 启动时向 LogCat 打印一些内容,但没有运行任何内容。这就是我想使用 Notification.deleteIntent 的方式吗?