Reputation: 336
If the notification is clicked the application will be opened only if it is was not on the background and if the app is on the background it will not be brought to foreground. Android platform.
Upvotes: 0
Views: 1557
Reputation: 331
In http v1 of firebase backend php code, if you comment the below line :
$d['android'] = ['notification' => ["click_action" => "FCM_PLUGIN_ACTIVITY"]];
It will solve the problem if you are using this plugin : "cordova-plugin-firebasex" as firebasex plugin handles click action.
Upvotes: 0
Reputation: 3011
<preference name="AndroidLaunchMode" value="singleTop" />
When you add this line in config.xml even then two cases can happen or these cases might also be happening without adding this line
you won't be able to receive notification when app is in background or killed
if you received background notification even then when you click on it. It won't open the respective application
So to solve first point, you should send the notification key whose value is object in object of fcm from backend service
So to solve second point, "click_action" key should not be passed in notification object
So your overall FCM object which is passed in fcm api should look like
{
"notification": {
"title": "Test Title",
"body": "message",
"sound": "default",
"icon": "fcm_push_icon",
"image": ""
},
"data": {
"action": "TEST"
},
"to":"caRvu_MeTN6HbMZKHfOO7y:APA91bEOEOAhpZNrDcDWew0uXM1HfKavyXbf3q4U090AHW5FmD7kDDxs4BRquaM*******************************************",
"priority": "high"
}
NOTE: This thing is only tested for Capacitor Fcm Plugin
Hope this will help you or somebody else :-)
Thanks!
Upvotes: 0
Reputation: 175
add this line in confix.xml
<preference name="AndroidLaunchMode" value="singleTop" />
and build app, works fine for me...
Upvotes: 1
Reputation: 7645
Had the same issue but from other reason. The app was not opened when the notification was clicked.
The problem was that I changed the plugin from cordova-plugin-fcm to cordova-plugin-firebase
And the server that send the notification set the click_action to FCM_PLUGIN_ACTIVITY
So I changed (php
):
$n = new Notification($title, $body);
return $n->setClickAction("FCM_PLUGIN_ACTIVITY")->setIcon('fcm_push_icon')->setSound('default');
To:
return $n->setIcon('fcm_push_icon')->setSound('default');
Upvotes: 2
Reputation: 336
So I spent a lot of time finding the bug changing parameters and it turned out that<preference name="AndroidLaunchMode" value="singleInstance"/>
parameter at config.xml was causing the problem. We used this parameter because deep links were creating new instances of the app. But for now we will ignore that problem.
Upvotes: 1