通知deleteIntent不起作用
我读过几个有关类似问题的问题,但它们没有为我提供解决方案。
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想将 Intent 与 BroadcastReceiver 一起使用,则应使用
PendingIntent.getBroadcast
而不是PendingIntent.getService
。您可能还需要设置适当的意图过滤器。If you want to use the intent with a BroadcastReceiver, you should use
PendingIntent.getBroadcast
instead ofPendingIntent.getService
. You might also need to setup an appropriate intent filter.