如何找到通知ID?

时间:2019-06-18 16:06:52

标签: android api android-notifications google-maps-android-api-2

如何获取要清除的标题或通知ID。 我的应用程序会产生几个通知。

Api是19。

使用NotificationListenerService有用吗?

1 个答案:

答案 0 :(得分:1)

是的,您可以使用getActiveNotifications中的NotificationListenerService来获取所有活动通知。

StatusBarNotification[] activeNotifications = service.getActiveNotifications();

然后循环浏览可用的通知并使用getId()

if(activeNotifications!=null){

  for(StatusBarNotification notification : activeNotifications ){

    if (notification.getId() == ID_TO_CHECK) {
       // do your operation
         }

   }
}