Android:如何从用户操作中区分从通知栏中清除所有事件 [英] Android: How to distinguish CLEAR all events from notification bar from user action

查看:42
本文介绍了Android:如何从用户操作中区分从通知栏中清除所有事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

According to the specification, .setDeleteIntent(pendingIntent) is associated to both actions (CLEAR all events from notification bar and user action like swiping).

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

My requirements are that when the user touches the notification that appears on the notification bar, he must be forwarded to the NotificationsList.class. This is done with my pendingInent:

PendingIntent sendPendingIntent = PendingIntent.getActivity(context, reminderId, new Intent(context, NotificationsList.class), PendingIntent.FLAG_UPDATE_CURRENT);

但是,在单击 CLEAR 按钮时,用户不得被导航到应用程序.使用 .setDeleteIntent(pendingIndent) 我无法满足第二个要求.用户仍被导航到 NotificationsList.class.

However, on clicking the CLEAR button, the user must not be navigated to the application at all. With the .setDeleteIntent(pendingIndent) I cannot fulfill the 2nd requirement. The user is still navigated to NotificationsList.class.

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

Is there a way to programmatically distinguish the CLEAR all notifications events fired from the CLEAR button from user actions like touch or swipe on the specific notification on the notification bar?

推荐答案

你所描述的是非常迟钝的行为.您只需将挂起的 Intent 设置为您的通知,当它被点击时,支持它的 Intent 将被执行.

What you're describing is very obtuse behavior. You need only set the pending intent to your notification and when it is clicked, the intent that is backing it will be executed.

如果您的代码在清除通知时引导用户返回应用,那么您的设计已经问题.如果用户清除了您的通知,您不应该尝试将它们导航回来.因此,setDeleteIntent() 不应与启动任何活动相关联.

If your code is navigating the user back to the app when the notification is cleared, then you already have a problem with your design. If the user clears your notification you should NOT be trying to navigate them back. Hence the setDeleteIntent() should NOT be associated with starting any activity.

注意点击通知时支持的意图(setContentIntent())和清除(setDeleteIntent())通知基本上是两个PendingIntent,他们应该不一样,这就是你的问题所描述的.

Note that the intent that is backed when you click the notification (setContentIntent()) and clear (setDeleteIntent()) the notification are basically two PendingIntents, they should not be the same, which is what your problem is describing.

这篇关于Android:如何从用户操作中区分从通知栏中清除所有事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆