我正在解析公开无效的onNotificationPosted(StatusBarNotification sbn)方法在Android中发布的应用通知。问题是,每当Whats App发布新的Whats App通知时,所有旧的未读通知都会重新发布到onNotificationPosted()方法中。因此,我最终再次解析了相同的通知。 通知对象中是否有唯一的值(例如时间戳),所以我可以知道是否已解析该通知。
以下是我正在使用的源代码:
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);
}
}
答案 0 :(得分:0)
有sbn.getPostTime吗?
发布通知的时间(以System#currentTimeMillis时间表示),可能与Notification.when不同。