FCM message processing
To receive messages, use a service that extends FirebaseMessagingService. Your service should override the onMessageReceived callback that is provided for most types of messages, with the following exceptions:
Notifications sent when your app is in the background. In this case, the notification is delivered to the system tray of devices. The user, by clicking on the notification, opens the default application launcher.
Messages with a payload of notifications and data, both in the background and in the foreground. In this case, the notification is delivered to the deviceโs system tray, and the data payload is delivered in addition to the purpose of your launch activity.
Types of messages:. With FCM, you can send two types of messages to clients:
- Notification messages, which are sometimes perceived as "display messages."
- Data messages that are processed by the client application.
The notification message is a lighter option with a 2 KB limit and a predefined set of user-visible keys. Data messages allow developers to send up to 4 KB of custom key-value pairs. Notification messages may contain an additional data payload that is delivered when users click on the notification.
To process notifications in the background, you need to send data in data messages
Example: -
{ "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "data" : { "Nick" : "Mario", "body" : "great match!", "Room" : "PortugalVSDenmark" }, }
Please check these links for more information: -
https://firebase.google.com/docs/cloud-messaging/android/receive
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages