I am working on App in which I am required to show notification. For notification, i am using FireBase Cloud Messaging (FCM). I am able to get Notification
With FCM, you can send two types of messages to clients:
1. Notification messages: sometimes thought of as "display messages."
FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.
2. Data messages: which are handled by the client app.
Client app is responsible for processing data messages. Data messages have only custom key-value pairs.
According to FCM document Receive Messages in an Android App
- Notifications 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.
Set click_action in the notification payload:
So, if you want to process the messages arrived in the background, you have to send click_action with message.
click_action is a parameter of the notification payload
If you want to open your app and perform a specific action, set click_action in the notification payload and map it to an intent filter in the Activity you want to launch.
For example, set click_action to OPEN_ACTIVITY_1 to trigger an intent filter like the following:
FCM payload looks like below:
{
"to":"some_device_token",
"content_available": true,
"notification": {
"title": "hello",
"body": "test message",
"click_action": "OPEN_ACTIVITY_1"
},
"data": {
"extra":"juice"
}
}