通知deleteIntent不起作用不起作用、通知、deleteIntent

2023-09-13 23:46:09 作者:浅爱べ莫相离

我读过有关similair问题的几个问题,但他们没有为我提供了解决方案。

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

在我的Andr​​oid应用我火了一个通知(在应用程序类是具体的,这实际上是从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).

然后,我想接收意向的时候,全部清除按钮pssed的通知$ P $:

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

    }
}

在我的清单文件我有:

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

但还是的onReceive不会被调用。我能是做错了什么?有没有什么聪明的方法来调试,并查看是否意图真的是发射?

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.