如何使用 FCM (Firebase Cloud Messaging) 制作紧凑的通知?

How to make a compact notification with FCM (Firebase Cloud Messaging)?

由于 FCM 不允许我发送 URL 类型 "icon",我试图在 "data" 类型的 FCM 消息到达时立即应用本地通知。但是 "data" 类型的消息在应用程序关闭时不会被处理,所以我不得不重用 "notification" 类型的消息。由于 "icon" 选项不适用于 URLs 我正在考虑使用 "image",但我只需要充当图标的小选项。有什么方法可以压缩消息,使其隐藏大图只显示小图吗?

就好像下图中的第二条消息,这个隐藏的大图再接收一条消息。

example image

通知在REST中的JSON结构如下:

{
    "to": "fVJq6D9...................................",
    "notification": {
        "title": "Title Message 2",
        "body": "Body Message 2",
        "image": "http://www.iconarchive.com/download/i65798/hopstarter/bioman/Bioman-Avatar-1-Red.ico"
    }
}

App的构建我使用的是Flutter

目前这是不可能的,因为您要动态设置的图标是由 setSmallIcon() 设置的小图标,根据其定义,它需要本地存储资源的 ID:

    /**
     * Set the small icon to use in the notification layouts.  Different classes of devices
     * may return different sizes.  See the UX guidelines for more information on how to
     * design these icons.
     *
     * @param icon A resource ID in the application's package of the drawable to use.
     */
    public Builder setSmallIcon(int icon) {
        mNotification.icon = icon;
        return this;
    }

您无法获取服务器获取的图片的id。相反,您可以尝试根据情况创建不同的通知,并在代码中设置相应的小图标。