【发布时间】: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