Which event is called when app is in background mode? - android

According to this, when the message is both a notification and data message and the app is in the background, the message is received as follows:
Notification: system tray
Data: in extras of the intent.
Which intent is it refering to?
From the Firebase Notification Console I sent a message with Custom data, ie with some Key/Value. Is this considered a combined Notification and Data message? My onMessageReceived event does not fire when the app is in the background. Only the notification shows in the Notification bar at the top.

Which intent is it refering to?
The intent that starts the activity. See my answer here.
From the Firebase Notification Console I sent a message with Custom data, ie with some Key/Value. Is this considered a combined Notification and Data message?
Yes. See my answer here.

Related

Action button is not showing in the notification when the application is in background

While sending the notification and when my application is in the foreground, i am getting the notification with the action buttons in the notification, while when my application is killed or in background the notification is coming but without the action button, i am getting just the title and content body.
I have tried many solution but it does work. Is android have new permission issues are introduced?
Any help and suggestion will be appreciated.Here is the Image
As there's no any code provided I can't say what's the specific issue here, butt keep in mind. In FCM there are 2 types of notifications:
Notification payload
Data payload
When you send a notification from FCM, it is a notification payload. In this case if your app is killed, the notification will go directly to the system tray and will be handled by the OS. The onMessageReceived() won't execute.
If you send the notification from the backend side, it's a data payload. In that case the onMessageReceived() will be executed.
Check more here FCM Message Types

Can I handle FCM notification message without data field in background state?

I have a problem that to handle FCM notification message.
I want to handle notification message without data fields.
So I've implement firebasemessagingservice in my project, but onMessageReceived function did not triggered.
Is it possible? Can I handle none data fields notification message in background state?
No, onMessageReceived only gets triggered in the background when you have a data payload, see the documentation for details.
If you only have a notification field, it will land in the system tray and be handled by system, if you still want to handle the notification yourself, change the message payload to data and just include the related notification information and push out a notification yourself, for more details, see documentation.
The documentation says you can do this with setBackgroundMessageHandler() which goes in the firebase-messaging-sw.js file.
I have never done it, but that is what the documentations says.

How to read the push Notification data from system tray.?

Is it possible to read the push notification information (Both notification {} and data{} from FCM), without tapping/clicking on the notifications. ?
As for the the Documentation, Notification come your app, either it is in foreground or background, But in these case of background, a 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 requirement is to read the notification without clicking on it.
Is it possible..? if yes please give me some information / some links.
You can use FCM data message instead of notification, everytime you receive a new data message onMessageReceived will be called and you can choose either to show this notification or not, and will get all relevant data.

Firebase custom data if App is Closed

I have used this How to get custom data from android firebase notification? solution for getting custom data from Firebase and it work only if Application is open, when Application is closed the custom data return empty String ""
Another question related if remove the code for notification from:
public void onMessageReceived(RemoteMessage remoteMessage) {
and application is closed i recevived always a notification but if open not?
I think if Application is open use my code but if closed what code use?
The callback onMessageReceived is only called when the application is running ie its in foreground.
according to https://firebase.google.com/docs/cloud-messaging/android/receive
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.
So the payload data you need to fetch using intent.getExtras()

Push Notifications to Android App

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.
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.

Categories

Resources