Групповое сообщение fcm от каждого чата отдельно - PullRequest
0 голосов
/ 01 апреля 2020

Мне уже удалось отправить / получить от / в группу fcm

Проблема:

Мне нужно собрать сообщение, приходящее из одной и той же группы. Например, Facebook Messenger: имя приложения, затем имя комнаты чата, затем сообщения из той же комнаты *

Пример: Мне нужно вместо текущих разделенных сообщений на прикрепленной фотографии:

Learning ways  <<the name of app
num2           <<room name 
Mon: 6         <<message1
Mon: 7         <<message2
Mon: 8         <<message3

Текущие уведомления Вызов:

  @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
    private void showOreoNotification() {


        OreoNotification oreoNotification = new OreoNotification(this);
        Notification.Builder builder = oreoNotification.getOreoNotification(title, sender_name + body, pendingIntent,
                defaultSound, icon).setLargeIcon(senderImages);
        oreoNotification.getManager().notify(i, builder.build());
        i++;
    }

  private void showOLdNotifications() {


        assert icon != null;
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(Integer.parseInt(icon))
                .setContentTitle(title)
                .setContentText(sender_name + body)
                .setAutoCancel(true)
                .setSound(defaultSound)
                .setContentIntent(pendingIntent).setLargeIcon(senderImages);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        assert notificationManager != null;
        notificationManager.notify(i, notificationBuilder.build());

        i++;
    }

text

1 Ответ

0 голосов
/ 16 апреля 2020

Вы можете использовать InboxStyle для Android 4.1 +

Формат сообщения:

val str1:String = "%s : %s".format(sender, message)

InboxStyle:

Notification notif = new Notification.Builder(mContext)
      .setContentTitle(room_name)
      .setContentText(subject)
      .setSmallIcon(R.drawable.icon)
      .setLargeIcon(aBitmap)
      .setStyle(new Notification.InboxStyle()
          .addLine(str1)
          .addLine(str2)
          .setContentTitle("")
          .setSummaryText("+1 more"))
      .build();

Вы можете использовать MessagingStyle для Android 7 +

var notification = NotificationCompat.Builder(this, CHANNEL_ID)
        .setStyle(NotificationCompat.MessagingStyle("me")
                .setConversationTitle(room_name)
                .addMessage(message1, timestamp1, null) // Pass in null for you.
                .addMessage(message2, timestamp2, user2)
                .addMessage(message3, timestamp3, user3)
        .build()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...