Android:如何区分CLEAR所有事件与通知栏和用户操作

gos*_*eib 6 notifications android clear android-notification-bar

根据规范,.setDeleteIntent(pendingIntent)与两个动作相关联(CLEAR来自通知栏的所有事件和用户动作,如滑动).

我的要求是当用户触摸通知栏上显示的通知时,必须将其转发到NotificationsList.class.这是通过我的pendingInent完成的:

PendingIntent sendPendingIntent = PendingIntent.getActivity(context, reminderId, new Intent(context, NotificationsList.class), PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)

但是,单击CLEAR按钮时,用户根本不能导航到应用程序.随着.setDeleteIntent(pendingIndent)我无法满足第二个要求.用户仍然导航到NotificationsList.class.

有没有办法以编程方式区分CLEAR从CLEAR按钮触发的所有通知事件与用户操作(如触摸或滑动通知栏上的特定通知)?

Jox*_*aex 3

你所描述的行为是非常迟钝的。您只需将待处理的意图设置为您的通知,当单击它时,支持它的意图将被执行。

如果您的代码在通知被清除时将用户导航回应用程序,那么您的设计已经存在问题。如果用户清除了您的通知,您不应该尝试将其导航回来。因此setDeleteIntent()不应与开始任何活动相关联。

请注意,当您单击通知(setContentIntent())并清除(setDeleteIntent())通知时支持的意图基本上是两个 PendingIntents,它们不应该相同,这就是您的问题所描述的。