If you want to open the application and perform a specific action [in the background], 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 trigger the intent filter as follows:
As stated in the FCM docs, ask the backend to send JSON data in a form like this,
{ "to":"some_device_token", "content_available": true, "notification": { "title": "hello", "body": "yo", "click_action": "OPEN_ACTIVITY_1" // for intent filter in your activity }, "data": { "extra":"juice" } }
and in your mainfest file add an intent filter for your activity as below
<intent-filter> <action android:name="OPEN_ACTIVITY_1" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
When you click on the notification, it will open the application and go to the action that you define in click_action, in this case "OPEN_ACTIVTY_1". And inside this activity you can get data:
Bundle b = getIntent().getExtras();// add these lines of code to get data from notification String someData = b.getString("someData");
Check out the links below for more help:
Firebase FCM click_action download notification
Firebase onMessageReceived is not called when the application is in the background
Firebase console: how to specify click_action for notifications
source share