rdrgtec
rdrgtec

Reputation: 640

FCM Notifications - how to change Icon?

I'm newbie on using FCM API for push notifications, but the documentation didn't seem very clear for me. I'm trying to find out what values are accepted by the notification data content. So far, I'm trying to use it on this way:

        const data: NotificationData = {
            notification : {
                title: "Test Notification",
                body: "Test Notification Body",
                icon: "http://localhost:3001/gmp-icon.png"
            },
            to: window.FCMToken,
        }

I'm posting it against the API url https://fcm.googleapis.com/fcm/send, and I wanted to format it as a web notification, but posteriorly as Android and iOS to be used from react-native.

Where should I add the icon value?

Upvotes: 1

Views: 3991

Answers (2)

Sumit Yadav
Sumit Yadav

Reputation: 44

Try to add an object in the body as "data" and this object will have the custom fields you want to send. And send the icon property in the data object. For ex:

{
"to" : "Token",
"notification" : {
    "title": "Title of the notification",
    "body": "Body of the notification",
    "data": {
      "click_action": "https://google.com",
      "customData": "valueOfCutomData",
      "image": "Some valid url",
      "icon": "Url of the icon",
      "url": "https://google.com"
    }
  }
}

Upvotes: 1

Anuj
Anuj

Reputation: 650

download png file and place file in android/app/src/main/res/drawable as notification_icon.png

<meta-data 
         android:name="com.google.firebase.messaging.default_notification_icon"
         android:resource="@drawable/ic_notification" />

Upvotes: 0

Related Questions