user4057066
user4057066

Reputation: 295

how to get timestamp of notification on android onNotificationPosted()

I am parsing whats app notifications posted in android in public void onNotificationPosted(StatusBarNotification sbn) method. The problem is whenever a new whats app notification is posted by whats app, all the old unread notifications are reposted to the onNotificationPosted() method. So I end up parsing the same notification again. Is there a unique value in the Notification object like a timestamp, so I can know if I have already parsed that notification.

Below is the source code I am using:

 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);
            }
           }

Upvotes: 1

Views: 1220

Answers (1)

Djaf
Djaf

Reputation: 256

There is sbn.getPostTime?

The time (in System#currentTimeMillis time) the notification was posted, which may be different than Notification.when.

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

Upvotes: 1

Related Questions