通知 deleteIntent 不起作用 [英] Notification deleteIntent does not work

查看:19
本文介绍了通知 deleteIntent 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几个关于类似问题的问题,但它们没有为我提供解决方案.

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

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

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).

然后我想在通知上按下全部清除"按钮时收到一个 Intent:

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);

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

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>

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

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?

欢迎提供任何提示.

推荐答案

如果你想使用 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.

这篇关于通知 deleteIntent 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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