如何将多个通知分组显示? [英] How to display multiple notification as a group?

查看:116
本文介绍了如何将多个通知分组显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的通知代码.每次

here is my code for notification. it generate a new notification each time

Random random = new Random();
int m = random.nextInt(9999 - 1000);    
NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.quemark1)
                    .setContentTitle("New Message")
                    .setContentText(message)
Intent intent = new Intent(this, ActivityMain.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(ActivityMain.class);
stackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager)     context.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
mBuilder.setAutoCancel(true);
mNotificationManager.notify(m, mBuilder.build());

这是我的代码的输出

推荐答案

它将生成包含Gmail之类的多条消息的通知

It will generate notification with multiple messages like Gmail

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.quemark1)
                    .setContentTitle("Title")
                    .setContentText("New Message received");
            NotificationCompat.InboxStyle inboxStyle =
                    new NotificationCompat.InboxStyle();

            inboxStyle.setBigContentTitle("doUdo");

           // Add your All messages here or use Loop to generate messages

                inboxStyle.addLine("Messgare 1");
                inboxStyle.addLine("Messgare 2");
                          .
                          .
                inboxStyle.addLine("Messgare n");


            mBuilder.setStyle(inboxStyle);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

            stackBuilder.addNextIntent(intent);

            PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            mBuilder.setContentIntent(pIntent);

            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
            mBuilder.setAutoCancel(true);
            mNotificationManager.notify(0, mBuilder.build());

这篇关于如何将多个通知分组显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆