2014-05-09 3 views
1

알림을 생성하고 응용 프로그램이 정상적으로 작동하는 Android 응용 프로그램을 개발하고 있지만 전화가 알림을 받고 다른 알림을 받으면 나중에 알림이 첫 번째 알림을 숨 깁니다 . 응용 프로그램이 많은 알림을 수신 할 때마다 모든 알림을 표시해야합니다. 나중에 하나만 표시하면 안됩니다. 어떻게 할 수 있습니까?동시에 여러 알림을 표시하는 방법

다음은 알림을 처리하는 코드입니다. 0는 알림 ID이다 notificationManager.notify(0, notification); 마지막 줄

private static void generateNotification(Context context, String 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, Activity_SplashScreen.class); 
    // 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);  

} 

답변

2

는 각 Notification에 대해 서로 다른 notification id을 통과해야합니다. 당신이 동일한 ID를 전달하는 경우 (즉, 귀하의 경우 0) 존재 notification

그래서, 예를 들어,이

notificationManager.notify(0, notification); 

변경 일부 고유 ID INT notificationId = 0x10으로 설정 새로운 데이터로 업데이트됩니다 ;

notificationManager.notify(++notificationId, notification); 

ID -의 S ame id has already been posted by your application과와 알림이 아직 취소되지 않은 경우 will be replaced by the updated information.

관련 문제