Firebasemessagingservice : Intent.putextra() Does Not Work If App Is Not Running
Solution 1:
After your second edit, we can see that you send both a notification and a data payload to FCM. If you check the FCM Documentation, you can see how the application will behave depending on being in the foreground or in the background. (Having your application killed is the same as running in the background.)
[Exception 2] 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.
This means that your onMessageReceived method is never called in this state. The FCM service internally creates a notification that starts your main activity and passes the data payload in the intent bundle automatically.
You should either handle this situation correctly, or use only data payloads to opt out of the built-in behavior.
Solution 2:
My first answer to your question which I ended up deleting as we both felt that in your case onMessageReceived() is called. But this is what it really is
onMessageReceived() method will not be called if the app is in background or killed and if the message sent contains DATA and NOTIFICATION payload both.
When app is not running you will anyway receive notification. But if you want to intercept data via onMessageReceived() then you will have to create a custom app server which will send only DATA payload to fcm endpoint.
something like this:
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data" : {
"Title" : "Title for Notification",
"body" : "Notification body can go here",
"Room" : "Something extra"
},
}
Hope this solves your issue.
EDIT: I just realized that if you want to send Notification and Data payload both while app is killed and in background then intent can be intercepted in launcher activitywhen user clicks on notification. By simply doing this:
IntentfcmIntent= getIntent();
But this will work only in Launcher Activity which the notification click is launching. You can simply put it in onCreate() method.
Post a Comment for "Firebasemessagingservice : Intent.putextra() Does Not Work If App Is Not Running"