Ad

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?

Ad

Answer

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"}
Ad
source: stackoverflow.com
Ad