如何获取要清除的标题或通知 ID。我的应用程序生成多个通知。
API 是 19 .
使用NotificationListenerService
有用吗?
是的,您可以使用 NotificationListenerService
中的getActiveNotifications
来获取所有活动通知。
StatusBarNotification[] activeNotifications = service.getActiveNotifications();
然后循环访问可用通知并使用getId()
if(activeNotifications!=null){
for(StatusBarNotification notification : activeNotifications ){
if (notification.getId() == ID_TO_CHECK) {
// do your operation
}
}
}