Notification deleteIntent does not work

為{幸葍}努か 提交于 2020-01-09 10:07:22

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8811876/notification-deleteintent-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!