如何在android中存储所有未读通知?

如何在android中存储所有未读通知?,android,Android,嗨 我是android新手,我在GCM中使用了通知,但问题是,当我一个接一个地发送多个通知时,当我向下滚动状态栏时,只有最后一个通知可用。我想在向下滚动状态栏时显示所有未读通知。 我的代码如下 private static void generateNotification(Context context, String message) { System.out.println("generateNotification() : "+message); Notifica

我是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);      

}
请帮助某人 提前感谢。

在您的代码中:

notificationManager.notify(0, notification);     
0参数对应于通知ID。为每个发送的通知指定不同的ID。文件规定:

API中添加的公共无效通知(int id,通知通知) 一级

发布要在状态栏中显示的通知。如果通知 您的应用程序已经发布了具有相同id的,并且 尚未取消,将由更新的信息替换。 参数id此通知的标识符在您的系统中是唯一的 应用通知描述要执行的操作的通知对象 显示用户。不能为null


非常感谢Nick T,它起作用了。但我仍然有一个问题,就是如何获取我为ex.notificationManager.notify(NotificationMessageModel.unreadNotification,notification)设置为特定消息的id;NotificationMessageModel.unreadNotification++;当我点击挂起的通知。嗨,我解决了这个问题。但是如果我添加了唯一的id来通知(id,msg)方法,那么它显示的图标数量取决于id。例如,如果我发送3个msg,那么在状态栏上它显示的是3个图标。我只想显示一个带有计数的图标。此页面处理多条消息的一个通知图标。