Android 通知收件箱样式
我想创建一个类似即时消息应用程序的东西。如何在一个通知中显示多条消息?我可以创建一个在用户收到单个通知时显示的通知。但是,当用户收到多条消息时,如何使用上一条消息更新通知?如果用户没有取消通知,我是否应该将消息保存到数据库中并显示出来?或者我还有别的办法处理这个问题吗 下面是我的通知代码Android 通知收件箱样式,android,notifications,push-notification,Android,Notifications,Push Notification,我想创建一个类似即时消息应用程序的东西。如何在一个通知中显示多条消息?我可以创建一个在用户收到单个通知时显示的通知。但是,当用户收到多条消息时,如何使用上一条消息更新通知?如果用户没有取消通知,我是否应该将消息保存到数据库中并显示出来?或者我还有别的办法处理这个问题吗 下面是我的通知代码 NotificationManager notificationManager = (NotificationManager) context.getSystemService(
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, "IMTest- A new event is created" , when);
Intent notificationIntent = new Intent(context, IM_Chat.class);
notificationIntent.putExtra("topicId", topicId);
notificationIntent.putExtra("sender", sender);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 1, notificationIntent, Intent.FLAG_ACTIVITY_MULTIPLE_TASK | PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, topicName, "A new event ["+eventName+"] is added in "+topicName, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.ledARGB |= 0xff0000ff;
notification.ledOffMS |= 1000;
notification.ledOnMS |= 300;
notificationManager.notify(CommunitiesappConstant.NOTIFICATION_ID, notification);
您可以使用相同的id和生成器更新通知
谢谢你的信息。我要试试看!但是,在更新通知之前,如何首先检查通知是否存在?我尝试了这个方法,只为一条消息创建了一个紧凑的通知。如何为收件箱通知样式实现此功能?
private NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
private mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//Different Id's will show up as different notifications
private int mNotificationId = 1;
//Some things we only have to set the first time.
private boolean firstTime = true;
private updateNotification(String message, int progress) {
if (firstTime) {
mBuilder.setSmallIcon(R.drawable.icon)
.setContentTitle("My Notification")
.setOnlyAlertOnce(true);
firstTime = false;
}
mBuilder.setContentText(message)
.setProgress(100, progress, true);
mNotificationManager.notify(mNotificationId, mBuilder.build());
}