【问题标题】:how to get timestamp of notification on android onNotificationPosted()如何在android onNotificationPosted()上获取通知的时间戳
【发布时间】:2020-04-06 00:13:20
【问题描述】:

我正在解析在 public void onNotificationPosted(StatusBarNotification sbn) 方法中发布在 android 中的应用程序通知。问题是每当什么应用程序发布新的什么应用程序通知时,所有旧的未读通知都会重新发布到 onNotificationPosted() 方法。所以我最终再次解析相同的通知。 Notification 对象中是否有唯一值,例如时间戳,所以我可以知道我是否已经解析了该通知。

下面是我正在使用的源代码:

 public void onNotificationPosted(StatusBarNotification sbn,NotificationListenerService.RankingMap rankingMap) {
        if(isWhatsAppNotification(sbn.getPackageName())) {

          Bundle extras = sbn.getNotification().extras;
          String title = extras.getString("android.title");
          String text = extras.getCharSequence("android.text").toString();

            Log.i("Text2222 Text", text);
            Log.i("Text2222 Title", title);
            }
           }

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    有sbn.getPostTime吗?

    发布通知的时间(以 System#currentTimeMillis 时间表示),可能与 Notification.when 不同。

    来自https://developer.android.com/reference/android/service/notification/StatusBarNotification#getPostTime()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      相关资源
      最近更新 更多