Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Cloud Messaging not getting the Android Icon in notification #1178

Closed
AugustoAleGon opened this issue Feb 24, 2021 · 6 comments
Closed

Comments

@AugustoAleGon
Copy link

Describe your environment

  • Operating System version: Mac
  • Firebase SDK version: ^9.4.2
  • Firebase Product: messaging
  • Node.js version: 12.16.3
  • NPM version: 6.14.8

Currently I am testing push notification on Android using the method .send in messages.
I already tested my client side with FCM console and the notification icon works perfect, also I used the method .sendToDeviceand is working fine.

In order to reproduce send I used this:

const note = {
    android: {
        priority: 'HIGH',
        data: {
            title: '#test',
            body: 'New message',
            icon: 'ic_notification',
            color: '#FFF',
            sound: 'default',
            tag: 'undefined',
            channelId: 'bundle.id,
            visibility: 'private',
            // image: '',
            host: 'http://localhost:3000/',
            type: 'p',
            name: 'test'
        },
        fcm_options: {
            analytics_label: 'click_notification'
        }
    },
    token: 'FCM_TOKEN'
};

admin.messaging().send(note)

The result is the following:

result

This actually what I got from FCM console:

expected_result

I also tried to remove the icon section as well. I got the same result.

@hiranya911
Copy link
Contributor

You are passing icon and other settings as part data. It should be set as part of notification:

https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidConfig#notification
https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidNotification

@AugustoAleGon
Copy link
Author

@hiranya911 I am checking the structure of the code and I don't see any icon label on the notification object.

This the notification object in your own library.

export interface Notification {

@AugustoAleGon
Copy link
Author

AugustoAleGon commented Feb 25, 2021

@hiranya911 I was testing your suggestion on the method send. The response is the following:

(node:21096) UnhandledPromiseRejectionWarning: Error: Invalid JSON payload received. Unknown name "icon" at 'message.notification': Cannot find field.

I am sending this payload:

const note = {
    notification: {
        icon: 'ic_notification'
    },
    android: {
        priority: 'HIGH',
        data: {
            title: '#test',
            body: 'New message',
            color: '#FFF',
            sound: 'default',
            tag: 'undefined',
            channelId: 'bundle.id,
            visibility: 'private',
            // image: '',
            host: 'http://localhost:3000/',
            type: 'p',
            name: 'test'
        },
        fcm_options: {
            analytics_label: 'click_notification'
        }
    },
    token: 'FCM_TOKEN'
};

admin.messaging().send(note)

@hiranya911
Copy link
Contributor

You're looking at the wrong type. Correct type is called AndroidNotification:

/**
* Represents the Android-specific notification options that can be included in
* {@link messaging.AndroidConfig}.
*/
export interface AndroidNotification {
/**
* Title of the Android notification. When provided, overrides the title set via
* `admin.messaging.Notification`.
*/
title?: string;
/**
* Body of the Android notification. When provided, overrides the body set via
* `admin.messaging.Notification`.
*/
body?: string;
/**
* Icon resource for the Android notification.
*/
icon?: string;
/**
* Notification icon color in `#rrggbb` format.
*/
color?: string;
/**
* File name of the sound to be played when the device receives the
* notification.
*/
sound?: string;
/**
* Notification tag. This is an identifier used to replace existing
* notifications in the notification drawer. If not specified, each request
* creates a new notification.
*/
tag?: string;
/**
* URL of an image to be displayed in the notification.
*/
imageUrl?: string;
/**
* Action associated with a user click on the notification. If specified, an
* activity with a matching Intent Filter is launched when a user clicks on the
* notification.
*/
clickAction?: string;
/**
* Key of the body string in the app's string resource to use to localize the
* body text.
*
*/
bodyLocKey?: string;
/**
* An array of resource keys that will be used in place of the format
* specifiers in `bodyLocKey`.
*/
bodyLocArgs?: string[];
/**
* Key of the title string in the app's string resource to use to localize the
* title text.
*/
titleLocKey?: string;
/**
* An array of resource keys that will be used in place of the format
* specifiers in `titleLocKey`.
*/
titleLocArgs?: string[];
/**
* The Android notification channel ID (new in Android O). The app must create
* a channel with this channel ID before any notification with this channel ID
* can be received. If you don't send this channel ID in the request, or if the
* channel ID provided has not yet been created by the app, FCM uses the channel
* ID specified in the app manifest.
*/
channelId?: string;
/**
* Sets the "ticker" text, which is sent to accessibility services. Prior to
* API level 21 (Lollipop), sets the text that is displayed in the status bar
* when the notification first arrives.
*/
ticker?: string;
/**
* When set to `false` or unset, the notification is automatically dismissed when
* the user clicks it in the panel. When set to `true`, the notification persists
* even when the user clicks it.
*/
sticky?: boolean;
/**
* For notifications that inform users about events with an absolute time reference, sets
* the time that the event in the notification occurred. Notifications
* in the panel are sorted by this time.
*/
eventTimestamp?: Date;
/**
* Sets whether or not this notification is relevant only to the current device.
* Some notifications can be bridged to other devices for remote display, such as
* a Wear OS watch. This hint can be set to recommend this notification not be bridged.
* See [Wear OS guides](https://developer.android.com/training/wearables/notifications/bridger#existing-method-of-preventing-bridging)
*/
localOnly?: boolean;
/**
* Sets the relative priority for this notification. Low-priority notifications
* may be hidden from the user in certain situations. Note this priority differs
* from `AndroidMessagePriority`. This priority is processed by the client after
* the message has been delivered. Whereas `AndroidMessagePriority` is an FCM concept
* that controls when the message is delivered.
*/
priority?: ('min' | 'low' | 'default' | 'high' | 'max');
/**
* Sets the vibration pattern to use. Pass in an array of milliseconds to
* turn the vibrator on or off. The first value indicates the duration to wait before
* turning the vibrator on. The next value indicates the duration to keep the
* vibrator on. Subsequent values alternate between duration to turn the vibrator
* off and to turn the vibrator on. If `vibrate_timings` is set and `default_vibrate_timings`
* is set to `true`, the default value is used instead of the user-specified `vibrate_timings`.
*/
vibrateTimingsMillis?: number[];
/**
* If set to `true`, use the Android framework's default vibrate pattern for the
* notification. Default values are specified in [`config.xml`](https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml).
* If `default_vibrate_timings` is set to `true` and `vibrate_timings` is also set,
* the default value is used instead of the user-specified `vibrate_timings`.
*/
defaultVibrateTimings?: boolean;
/**
* If set to `true`, use the Android framework's default sound for the notification.
* Default values are specified in [`config.xml`](https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml).
*/
defaultSound?: boolean;
/**
* Settings to control the notification's LED blinking rate and color if LED is
* available on the device. The total blinking time is controlled by the OS.
*/
lightSettings?: LightSettings;
/**
* If set to `true`, use the Android framework's default LED light settings
* for the notification. Default values are specified in [`config.xml`](https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml).
* If `default_light_settings` is set to `true` and `light_settings` is also set,
* the user-specified `light_settings` is used instead of the default value.
*/
defaultLightSettings?: boolean;
/**
* Sets the visibility of the notification. Must be either `private`, `public`,
* or `secret`. If unspecified, defaults to `private`.
*/
visibility?: ('private' | 'public' | 'secret');
/**
* Sets the number of items this notification represents. May be displayed as a
* badge count for Launchers that support badging. See [`NotificationBadge`(https://developer.android.com/training/notify-user/badges).
* For example, this might be useful if you're using just one notification to
* represent multiple new messages but you want the count here to represent
* the number of total new messages. If zero or unspecified, systems
* that support badging use the default, which is to increment a number
* displayed on the long-press menu each time a new notification arrives.
*/
notificationCount?: number;
}

@hiranya911
Copy link
Contributor

I was testing your suggestion on the method send. The response is the following:

Your payload is still incorrect. Please take another look at the API reference docs I've linked above. You can also find an example involving the icon setting here:

https://firebase.google.com/docs/cloud-messaging/send-message#example-notification-message-with-platform-specific-delivery-options

@AugustoAleGon
Copy link
Author

Ohh I see. You are totally right. I was sending the information wrong. Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants