2014-02-15 4 views
0

안녕하세요,읽지 않은 알림을 모두 Android에 저장하는 방법은 무엇입니까?

저는 안드로이드에서 새로운데 GCM과 함께 알림을 사용했습니다. 그러나 문제는 상태 표시 줄 아래로 스크롤 할 때 하나 이상의 알림을 하나씩 보내면 마지막 하나만 사용할 수 있다는 것입니다. 상태 표시 줄을 아래로 스크롤 할 때 읽지 않은 모든 알림을 표시하고 싶습니다. 내 코드는 다음과 같습니다.

private static void generateNotification(Context context, String message) { 
    System.out.println("generateNotification() : "+message); 
    NotificationMessageModel.msg=message; 
    int icon = R.drawable.ic_launcher; 
    long when = System.currentTimeMillis(); 
    NotificationManager notificationManager = (NotificationManager) 
      context.getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notification = new Notification(icon, message, when); 

    String title = context.getString(R.string.app_name); 

    Intent notificationIntent = new Intent(context, HomeActivity.class); 
    notificationIntent.putExtra("message", message); 
    // set intent so it does not start a new activity 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
      Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent intent = 
      PendingIntent.getActivity(context, 0, notificationIntent, 0); 
    notification.setLatestEventInfo(context, title, message, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 

    // Play default notification sound 
    notification.defaults |= Notification.DEFAULT_SOUND; 

    //notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3"); 

    // Vibrate if vibrate is enabled 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 
    notificationManager.notify(0, notification);  

} 

도와주세요 미리 감사드립니다. 코드에서

답변

1

:

notificationManager.notify(0, notification);  

0으로부터 인수는 알림 ID에 해당합니다. 보내시는 통지마다 다른 ID를 지정하십시오. 문서 상태 :

공공 무효가 통지 (INT 아이디, 알림 통지) API 레벨 1

포스트 통지에 추가 상태 표시 줄에 표시합니다. 동일한 ID를 가진 알림이 이미 신청서에 게시되어 있고 이 취소되지 않은 경우 업데이트 된 정보로 대체됩니다. 매개 변수 id 애플리케이션 내에서 고유 한이 알림의 식별자입니다. notification 에게 사용자를 표시 할 대상을 설명하는 알림 객체입니다. null 일 수 없습니다.

+0

고맙습니다. Nick T, 그 작업. 하지만 여전히 나는 문제에 대해 어떻게 전 특정 메시지를 설정 id를 얻을. notificationManager.notify (NotificationMessageModel.unreadNotification, notification); NotificationMessageModel.unreadNotification ++; 보류중인 알림을 클릭하면 – Delan

+0

안녕하세요, 저는이 문제를 해결합니다. 하지만 (id, msg) 메소드를 통보하기 위해 고유 한 ID를 추가하면 ID 번호에 따라 아이콘의 수가 표시됩니다. 예를 들어. 3 메시지를 보내면 상태 표시 줄에 아이콘이 3 개 표시됩니다. 개수가 하나 인 아이콘 만 표시하고 싶습니다. – Delan

+0

이 페이지 http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating 여러 메시지에 대해 하나의 알림 아이콘이있는 것을 다룹니다. – NickT

관련 문제