open a specific activity from firebase notification
original source : https://stackoverflow.com/questions/39663601/open-a-specific-activity-from-firebase-notification
If you want to open your app and perform a specific action [while backgrounded], 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:
As suggested in react-native-fcm docs,ask backend to send json data in the 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 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 the notification, it will open the app and go straight to activity that you define in click_action, in this case “OPEN_ACTIVTY_1”. And inside that activity you can get the data by :
Bundle b = getIntent().getExtras();// add these lines of code to get data from notification
String someData = b.getString("someData");
check out below links for more helps:
Firebase FCM notifications click_action payload
Firebase onMessageReceived not called when app in background
Firebase console: How to specify click_action for notifications