Alireza Noorali
Alireza Noorali

Reputation: 3265

How to set custom layout for those notifications which will be shown when app is in background?

I implemented the firebase cloud messaging (FCM) service in my app and I get notifications with my custom layout but just when the app is in the foreground and the reason is clear, It is because of existing setCustomContentView(myContentView) in onMessageReceived and we all know that onMessageReceived handle notification just when the app is in the foreground.

Now, I'm going to know is there a way to set the same custom layout for the notifications which will be shown when the app is in the background?

Upvotes: 1

Views: 1184

Answers (2)

Cuong Nguyen
Cuong Nguyen

Reputation: 1018

FCM has two messages types: when your app is in the background.

  • Notification message: enter image description here

  • Data message: enter image description here

    1. Notification message: the notification is delivered to the device’s system tray, not onMessageReceived

    2. Data message: always, the notification is delivered to onMessageReceived As image

so, You should send a format is Data Message to handle notification in onMessageReceived when the app is background or foreground

Upvotes: 2

Dhaval Solanki
Dhaval Solanki

Reputation: 4705

I would advise to modify server code to receive data onMessageReceived in both foreground and background and ask sender to send only data payload without notification.

Here I have removed notification payload.

{"to":"[add your token]","data":{"title":"Working Good","body":"[add your message]"},"priority":"high"}

Upvotes: 1

Related Questions