ChatApp:多行通知

时间:2017-07-27 18:24:30

标签: android firebase notifications firebase-cloud-messaging google-cloud-functions

我正在使用Firebase创建聊天应用程序。我使用Firebase云功能发送通知并在手机上接收它们。但对于每条消息,我都会收到新的通知。现在我想知道是否可以在WhatsApp中创建一个通知,在一个通知中为每条消息添加多行。我的通知代码:

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    String notification_tag = remoteMessage.getData().get("senderUiD");

        Intent intent = new Intent(getApplicationContext(), Chat_Room.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(remoteMessage.getData().get("username"))
                .setContentText(remoteMessage.getNotification().getBody())
                .setVibrate(new long[]{1500, 0, 1500, 0})
                .setLights(Color.BLUE, 2000, 1000)
                .setWhen(remoteMessage.getSentTime())
                .setAutoCancel(true)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody()))
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setContentIntent(pendingIntent);

        notificationManager.notify(notification_tag, 0, notificationBuilder.build());

感谢您的帮助;)

1 个答案:

答案 0 :(得分:0)

当您收到Notification留言时Notification覆盖最后Notification

生成Rendam编号

Random ran = new Random();
int notification_tag = r`an.nextInt(6) + 5;`

notificationManager.notify(notification_tag, 0, notificationBuilder.build());

另外,休息几步以进行分组通知

NotificationCompat.Builder:contains the UI specification and action information
NotificationCompat.Builder.build() :used to create notification (Which returns Notification object)
Notification.InboxStyle: used to group the notifications belongs to same ID
NotificationManager.notify():to issue the notification.