With FCM, you can send two types of messages to clients:
1. Notification messages: sometimes considered a “message display”.
FCM automatically displays a message to end-user devices on behalf of the client application. Notification messages have a predefined set of keys visible to the user.
2. Data messages: that are processed by the client application.
The client application is responsible for processing data messages. Data messages have only user key-value pairs.
According to FCM Document Receive Messages in Android App
- Notifications are delivered when your application is in the background. In this case, the notification is delivered to the system tray of devices. When a user clicks on a notification, the application launch bar opens by default.
- Messages with notification and data payload, both background and front. In this case, the notification is delivered to
The system tray of devices, and data is downloaded in additions about the intentions of your Activity launcher.
Set click_action
in the notification:
So, if you want to process messages that arrived in the background, you must send click_action
with the message.
click_action
is a notification payload parameter
If you want to open your application and perform a specific action, set click_action
in the notification payload and map it to the intent filter in the action you want to run.
For example, set click_action
to OPEN_ACTIVITY_1
to activate the intent filter, as shown below:
<intent-filter> <action android:name="OPEN_ACTIVITY_1" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
The FCM payload is as follows:
{ "to":"some_device_token", "content_available": true, "notification": { "title": "hello", "body": "test message", "click_action": "OPEN_ACTIVITY_1" }, "data": { "extra":"juice" } }