android - 通知 deleteIntent 不起作用

标签 android notifications broadcastreceiver

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

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

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

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

    }
}

在我的 list 文件中我得到了:

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

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

我需要某种 Intent 过滤器还是应该没问题?

欢迎任何提示。

最佳答案

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

关于android - 通知 deleteIntent 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8811876/

相关文章:

android - 在某些日子设置安卓闹钟管理器

android - 如何在列表 fragment 中使用 AsyncTask 实现进度条?

android - 如何从应用程序类中注销广播接收器?

android - 断开 USB 电缆时完成 Activity

android - 更多发送和接收广播的方式

android - 无法解析 : firebase-iid-interop

android - 在android中的每个选项卡旁边添加按钮

c# - ios webview - 如何在应用程序未运行时检查通知

c# - 从通用 Windows 平台 (UWP) 应用程序向 Azure 通知中心发送通知

iphone - 将 NSData 序列化为十六进制字符串的最佳方法