通知deleteIntent不起作用

发布于 2024-12-26 07:31:11 字数 775 浏览 0 评论 0原文

我读过几个有关类似问题的问题,但它们没有为我提供解决方案。

在我的 Android 应用程序中,我触发了一个通知(具体来说,在 Application 类中,它实际上是从 C2DM 推送事件启动的)。

然后,当在通知上按下“清除所有”按钮时,我想收到一个意图:

notification.deleteIntent = PendingIntent.getService(this, 0, new Intent(this, NotificationDeleteReceiver.class), 0);

在我的NotificationDeleteReceiver.class中,我得到了onReceive方法:

public class NotificationDeleteReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
}

在我的清单文件中,我得到了:

<receiver android:name="NotificationDeleteReceiver">
</receiver>

但onReceive仍然没有被调用。我可能做错了什么?有没有什么聪明的方法来调试并查看 Intent 是否真的被触发?

我是否需要某种意图过滤器或者应该没问题?

欢迎任何提示。

I've read several questions concerning similair issues, but they do not provide me with the solution.

In my Android app I fire off a notification (in the Application class to be specific, which is actually started from a C2DM push event).

I then want to receive an Intent when the "clear all" button is pressed on the notifications:

notification.deleteIntent = PendingIntent.getService(this, 0, new Intent(this, NotificationDeleteReceiver.class), 0);

In my NotificationDeleteReceiver.class I got the onReceive method:

public class NotificationDeleteReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
}

In my manifest file I got:

<receiver android:name="NotificationDeleteReceiver">
</receiver>

But still onReceive does not get called. What could I be doing wrong? Is there any smart way to debug and see if an Intent really is fired?

Do I need some kind of intent filter or should it be fine?

Any tips welcome.

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

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

发布评论

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

评论(1

罪#恶を代价 2025-01-02 07:31:11

如果您想将 Intent 与 BroadcastReceiver 一起使用,则应使用 PendingIntent.getBroadcast 而不是 PendingIntent.getService。您可能还需要设置适当的意图过滤器。

If you want to use the intent with a BroadcastReceiver, you should use PendingIntent.getBroadcast instead of PendingIntent.getService. You might also need to setup an appropriate intent filter.

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