2014-05-23 3 views
6

누구든지 ID로 알림을받을 수있는 방법을 알고 있습니까? Android의 상태 표시 줄에 여전히 표시되는 경우 새 알림을 받으면 정보를 가져 와서 새 알림에 추가하려고합니다. 고맙습니다.알림 관리자 ID로 알림 얻기

답변

11

NotificationManager는 기존 알림을 ID로 찾는 방법을 제공하지 않습니다. 알림을 업데이트하려면 새 알림을 게시하고 동일한 ID를 사용하십시오. 새로운 것으로 표시하거나 기존 알림을 해당 ID로 업데이트합니다.

+0

이렇게하면 이전 알림이 대체됩니까? –

+1

문서에서 직접 : "동일한 ID를 사용하는 알림이 애플리케이션에서 이미 게시되어 취소되지 않은 경우 업데이트 된 정보로 바뀝니다." https://developer.android.com/reference/android/app/NotificationManager.html#notify(int,%20android.app.Notification) – Karakuri

+4

감사합니다. Karakuri, sharedpreferences를 사용하여 문제를 해결했습니다. 데이터를 저장하고 사용합니다. 최신 정보. –

0

NotificationManager에서 활성 알림 목록을 가져올 수 있습니다.

public boolean isNotificationActive(int notificationId) { 
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    StatusBarNotification[] barNotifications = notificationManager.getActiveNotifications(); 
    for(StatusBarNotification notification: barNotifications) { 
     if (notification.getId() == notificationId) { 
      return true; 
     } 
    } 
    return false; 
} 
+1

에는 API 23 이상이 필요합니다. – SolidSnake