通知自动取消不叫DeleteIntent [英] Notification Auto-Cancel does not call DeleteIntent

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

问题描述

我实施GCM在我的应用程序,并保持通知的哈希值跟踪的是什么通知阴凉处(我不得不改变基于意图,如果用户在应用程序或流出)。

I'm implementing GCM in my app and keeping a hash of notifications to keep track of what is in the notification shade (I have to change intents based on if the user is in or out of app).

我设置deleteIntent PendingIntent我的所有通知。所有这一切确实是从我的本地哈希删除通知,这样就不会再被更新。如果我清除所有或轻扫删除通知的意图是解雇的罚款。不过,我也把我的通知自动取消。点击一个通知不会触发deleteIntent我的通知。

I set the deleteIntent PendingIntent for all my notifications. All this does is remove the Notification from my local hash so it won't be updated anymore. The intent is fired fine if I clear all or swipe to delete a notification. However, I also set my notifications to auto cancel. Clicking on a notification does not trigger the deleteIntent for my notification.

我的问题是,有没有办法得到通知时,我的通知是自动取消吗?

My question is, is there any way to be notified when my Notifications are auto-cancelled?

推荐答案

这个错误已经报道的,但它并不像已经研究在所有。要解决此这里就是我所做的:

This bug has been reported, but it doesn't look like it has been investigated at all. To work around this here's what I did:

  • 关闭自动取消
  • 使用广播的内容和删除意图用不同的动作
  • 广播接收机检查行动
    • 内容的行动:两者都做单击和删除操作,而手动取消通知
    • 删除操作:执行删除操作仅
    • Turn off auto cancel
    • Use broadcast for both content and delete intents with different actions
    • Broadcast receiver checks action
      • Content action: Do both click and delete operations, and cancel notification manually
      • Delete action: Do delete operation only

      例如:

      Notification.Builder builder = new Notification.Builder(context)
          // Set other properties (not auto-cancel)
          .setContentIntent(PendingIntent.getBroadcast(context, 0, new Intent(NOTIFICATION_CLICKED_ACTION), 0))
          .setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(NOTIFICATION_DELETED_ACTION), 0));
      notificationManager.notify(NOTIFICATION_ID, builder.build());
      

      接收广播

      if (intent.getAction().equals(NOTIFICATION_CLICKED_ACTION)) {
          startActivity(new Intent(context, MyActivity.class));
          notificationManager.cancel(NOTIFICATION_ID);
      }
      // Do deletion behaviour here (for both click and delete actions)
      

      这篇关于通知自动取消不叫DeleteIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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