【问题标题】:Flutter: How to define notification channel in firebase_messaging package?Flutter:如何在 firebase_messaging 包中定义通知通道?
【发布时间】:2021-05-22 13:33:34
【问题描述】:

我正在将此 json 发送到云消息传递(带有正确的标头)并希望在我的设备上获得通知,但它没有出现在我的手机上。我想也许我缺少 Android 的频道 ID 初始化?

*附加信息

  • 如果我发送带有标题或正文的“通知”有效负载,它正在接收,但我不想使用“通知”有效负载。我只想拥有“数据”负载
{
"to" : "my device token",
"mutable_content" : true,
"content_available": true,
    "data" : {
        "content": {
            "id": 100,
            "channelKey": "basic_channel",
            "title": "Huston!\nThe eagle has landed!",
            "body": "A small step for a man, but a giant leap to Flutter's community!",
            "notificationLayout": "BigPicture",
            "largeIcon": "https://media.fstatic.com/kdNpUx4VBicwDuRBnhBrNmVsaKU=/full-fit-in/290x478/media/artists/avatar/2013/08/neil-i-armstrong_a39978.jpeg",
            "bigPicture": "https://www.dw.com/image/49519617_303.jpg",
            "showWhen": true,
            "autoCancel": true,
            "privacy": "Private"
        },
        "actionButtons": [
            {
                "key": "REPLY",
                "label": "Reply",
                "autoCancel": true,
                "buttonType":  "InputField"
            },
            {
                "key": "ARCHIVE",
                "label": "Archive",
                "autoCancel": true
            }
        ]
    }
}

【问题讨论】:

    标签: android firebase flutter firebase-cloud-messaging


    【解决方案1】:

    要定义通知通道,您必须转到 AndroidManifest.xml 并在应用程序组件中添加此元:

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id"/>
    

    然后在您的 strings.xml 文件中输入频道 ID,如下所示:

    <string name='default_notification_channel_id'>Channel ID</string>
    

    完成此操作后,您可以在 FCM 控制台中定义您的频道 ID。

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 2019-09-26
      • 2019-10-31
      • 2021-08-09
      • 2020-09-28
      • 2019-12-29
      • 2017-04-23
      • 1970-01-01
      • 2021-07-24
      相关资源
      最近更新 更多