firebase-cloud-messaging - 将来自每个聊天室的 fcm 消息单独分组
问题描述
我已经成功地从/向组 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++;
}
解决方案
您可以在 Android 4.1+ 上使用 InboxStyle
留言格式:
val str1:String = "%s : %s".format(sender, message)
收件箱样式:
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();
您可以在 Android 7+上使用MessagingStyle
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()
推荐阅读
- next.js - 编写单元测试时使用 ProxyQuire 调用动态 Next JS 路由时出错
- javascript - 是否可以将 cookie 附加到脚本标签?
- django - Django-允许同时上传图像和文本?
- vba - VBA 从后台使用 Outlook 发送电子邮件
- python - InvalidSyntax:第 1 行的语法无效
- c# - C# .Net SIMD System.Numerics.Vector4 比循环慢
- java - PayPal SDK INTERNAL_SERVER_ERROR
- reactjs - Typescript jsx 标签不等于 React.createElement?
- python - 如何使协议上的“isinstance”还包括函数签名和数据类型?
- javascript - 如何在html和纯javascript中查找元素是否隐藏