Android 捕获通知事件(长按)

发布于 2024-11-29 00:58:56 字数 102 浏览 1 评论 0原文

对通知的标准短按会触发其中保存的 PendingIntent。

是否可以捕获其他事件?

要求是捕获长按。

The standard short click on a Notification fires the PendingIntent held in it.

Is it possible to catch other events?

The requirement is to catch a Long Press.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2024-12-06 00:58:56

尽管您可以使用 NotificationCompatRemoteViews 您无法操纵底层点击行为。您唯一的选择就是更改少数 ViewType 的一些参数:

因此回答您的问题:不,使用最新的 Google API (api lvl 17 - 14.01.2013) 您无法插入onLongClickListener 到通知中的任何视图元素中。

为什么会这样?

RemoteView 只是视图的简化、更简单的派生。它甚至与视图(RemoteView 扩展对象)无关,因此不提供真实视图中的所有选项(View.setOnLongClickListener()) 。

什么是 RemoteView?

RemoteView 可以由具有相同权限的另一个进程执行
原始应用程序(这就是它们被称为远程视图的原因)。这
小部件和通知以其定义应用程序的权限运行的方式。

从 ICS 开始,长按通知会触发“应用程序信息”
选项,这样您就可以看到哪个应用程序正在发送它(有助于识别
垃圾邮件应用程序)此外,从 JellyBean 开始,您还丰富了
通知允许您执行许多操作,包括多个操作
行动,也许你可以解决你的问题。

沙拉菲

如果您想获得更多见解,我推荐这些文章:

Although you can create custom Notification-Views with NotificationCompat and RemoteViews you have no means to manipulate underlying click-behavior. The only options you have got is to change some parameters for a handfull of ViewTypes:

So to answer your Question: No, with the most current Google API (api lvl 17 - 14.01.2013) you can not insert a onLongClickListener into any of the view-elements within a notification.

Why is this so?

RemoteView is only a boiled down, simpler derivate of a View. It is not even related to View (RemoteView extends Object) therefore does not provide all the options you would have in a real View (View.setOnLongClickListener()) .

What are RemoteViews?:

A RemoteView can be executed by another process with the same permissions as the
original application(that is why they are called Remote Views). This
way widgets and notifications run with the permissions of its defining application.

From ICS on, long press on a notification triggers the "App Info"
option, so you can see which app is sending it (useful to identify
spamming apps) Also, from JellyBean on, you have enriched
notifications that allow you to do many things, including more than one
action, probably you can solve your problem with that.

Shalafi

If you want more insight I recommend these articles:

软糯酥胸 2024-12-06 00:58:56

就像应用程序小部件一样,它是远程视图,仅支持点击和垂直拖动手势

Just like an app-widget, it's a remote view, it only supports tap and vertical drag gesture

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文