I know that Handle messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.
This includes messages that contain both notification and data payload. In these cases, 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.
but my app should detect when notification arrive to do operation (get data from server) because when notification arrive must load data but , when app in background i cannot know notification arrive till user click notification will app open and i will load data , but in some case user not click notification so data not loaded
so my question any way to KNOW when app receive notification in case app in background ?
You will get the call on the callback method onMessageReceived
in the FirebaseMessagingService in any case weather the app is in background or in foreground if and only if you are sending the data on "data" key. For example -
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data":{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}
}
}
You can show custom notification by creating it on the callback method onMessageReceived
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With