You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过FCM Admin SDK发送MessagingStyle样式通知?

问题与实现方案

当前实现方式

我目前通过向设备发送仅数据消息,然后在onBackgroundMessage回调中借助flutter_local_notifications插件,以MessagingStyle样式展示通知。

当前FCM请求JSON示例

{
    "token": "token",
    "data": {
      "foo": "bar"
    },
    "android": {
      "priority": "high"
    }
}

Android端代码示例

MessagingStyleInformation messagingStyleInformation =
      MessagingStyleInformation(
          conversationTitle: name,
          Person(name: name),
          messages: messages);

AndroidNotificationDetails notificationAndroidSpecifics =
    AndroidNotificationDetails(channelId, channelName,
        styleInformation: messagingStyleInformation,
        channelDescription: channelDescription,
        groupKey: groupKey,
        tag: id);

NotificationDetails notificationDetails =
    NotificationDetails(android: notificationAndroidSpecifics);

await flutterLocalNotificationsPlugin!.show(
    id,
    name,
    "last message",
    notificationDetails);

存在的问题

尽管目前还未出现限流情况,但仅数据消息优先级较低,存在被设备限流的风险,因此希望找到正确展示MessagingStyle通知的方法。

尝试的方案

我考虑直接通过FCM的通知配置指定样式,示例如下:

{
    "token": "token",
    "android": {
       "notification": {
          "style": "MessagingStyle"
       }
    }
}

内容的提问来源于stack exchange,提问作者flutroid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 00:29:55