有没有人知道如何通过id获取通知?当我得到一个新的通知时,如果它仍然显示在Android的状态栏中,我想要获取信息并将其添加到新的通知中。谢谢。
发布于 2014-05-23 22:34:03
NotificationManager不提供按ID查找现有通知的方法。如果您要更新通知,请发布新通知,但使用相同的ID。它会将通知显示为新通知或使用该ID更新现有通知。
发布于 2017-11-17 15:35:48
您可以从NotificationManager获取活动通知列表。
@RequiresApi(api = Build.VERSION_CODES.M)
public Notification getActiveNotification(int notificationId) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] barNotifications = notificationManager.getActiveNotifications();
for(StatusBarNotification notification: barNotifications) {
if (notification.getId() == notificationId) {
return notification.getNotification();
}
}
return null;
}https://stackoverflow.com/questions/23831214
复制相似问题