Reputation: 4007
I have an android app connected to FCM(firebase cloud messaging) for sending notifications . However , when the app is in background , it doesn't apply custom notifications. I think this is because it does not enter OnMessageReceived method . Whats the solution for this ? As i read somewhere it can be done using HTTP Api but i am not sure of how to go about it ? Please help.Thank you.
Upvotes: 0
Views: 108
Reputation: 9190
Whether the method onMessageReceived
is called is dependent on the notification payload.
See 'Handling Messages' section in FCM docs here.
Handling messages
onMessageReceived is provided for most message types, with the following exceptions:
Notification messages delivered when your app is in the background. In this case, the notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default. Messages with both notification and data payload, both background and foreground. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
In summary, if the app is in foreground, then onMessageReceived
will always be called. If the app is in background, then onMessageReceived
will only be called if the notification payload is data
only.
So to answer your question, if you must have onMessageReceived
every time regardless if the app is in foreground or background state, then set your notification payload to contain data
only.
Upvotes: 1