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

453

Currently this is not possible as the icon you want to set dynamically is the small icon set by setSmallIcon()which requires id to a locally stored resource as from it's definition:

    /**
     * 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;
    }

You cannot get the id the an image fetched by server. Instead, you can try to create different notifications depending upon cases with corresponding small icons set in the code.

Share:
453
anonimo3.0
Author by

anonimo3.0

Updated on December 13, 2022

Comments

  • anonimo3.0
    anonimo3.0 over 1 year

    Since FCM does not let me send a URL type "icon", I was trying to apply local notifications as soon as messages arrived by FCM of type "data". But messages of type "data" are not handled when the application is closed, so I had to reuse those of type "notification". Since the "icon" option does not work with URLs I was thinking of using "image", but I only need the small one that acts as an icon. Is there any way to compact the message so that it hides the large image and only shows the small one?

    It would be something like the second message in the image below, this hidden big image to receive another message.

    example image

    The JSON structure of the notification in REST is as follows:

    {
        "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"
        }
    }
    

    For the construction of the App I am using Flutter.

  • anonimo3.0
    anonimo3.0 over 4 years
    It is a messaging application, so the icon will correspond to the avatar of a contact. I think it would not be optimal to store the photo of each contact on the phone, so I wanted to get them via URL. Personalized notifications can be created without problem when the app is in foreground or minimized by receiving them through FCM and creating them with this plugin pub.dev/packages/flutter_local_notifications, but if it is closed the data is not received, as already warns in the documentation :(