Cordova-plugin-firebase: Tapping notification does not move the app to foreground (Android)

Created on 7 Mar 2018  ·  4Comments  ·  Source: arnesson/cordova-plugin-firebase

I open my app, put it in background by pressing home button and send a notification (via this service). The notification is received and is shown in the statusbar. But nothing happens when I tap on the notification - I get back to home screen and the app is not shown.

If the app is in foreground, 'onNotificationOpen' callback works as expected and I can see notification object.

The code (called inside 'deviceready' handler):

    window.FirebasePlugin.onTokenRefresh(function(token) {
       console.log('FirebasePlugin onTokenRefresh - token:', token);
    }, console.log);
    window.FirebasePlugin.onNotificationOpen(function(notification) {
        console.log('FirebasePlugin onNotificationOpen - notification:', notification);
    }, console.log);

cordova: 8.0.0
cordova android: 6.4.0
device: HTC 10 with Android 7.0

plugin list:
cordova-plugin-battery-status 1.2.5 "Battery"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-contacts 2.3.1 "Contacts"
cordova-plugin-device 1.1.7 "Device"
cordova-plugin-device-motion 1.2.5 "Device Motion"
cordova-plugin-device-orientation 1.0.7 "Device Orientation"
cordova-plugin-dialogs 1.3.4 "Notification"
cordova-plugin-directions 0.4.4 "Directions"
cordova-plugin-facebook4 1.9.1 "Facebook Connect"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-firebase 0.1.25 "Google Firebase Plugin"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-globalization 1.0.9 "Globalization"
cordova-plugin-inappbrowser 1.7.2 "InAppBrowser"
cordova-plugin-media 3.0.1 "Media"
cordova-plugin-media-capture 1.4.3 "Capture"
cordova-plugin-network-information 1.3.4 "Network Information"
cordova-plugin-statusbar 2.4.1 "StatusBar"
cordova-plugin-vibration 2.1.6 "Vibration"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-plugin-x-socialsharing 5.3.2 "SocialSharing"
cordova-push-notifications 1.2.4 "Push Notifications Plugin"
cordova-social-vk 1.0.5 "SocialVk"
es6-promise-plugin 4.2.2 "Promise"
ionic-plugin-keyboard 2.2.1 "Keyboard"

messaging android

Most helpful comment

Oh well.

What I had to do was to change payload format.
Other suggested removing "notification" entirely and move title and body inside data.
But it caused same issue - tapping not open app - on iOS.

I guess click_action => FCM_PLUGIN_ACTIVITY is causing problem.
To be safe, I removed all others except title and body from notification.

BEFORE

$data = json_encode([
"notification" => [
"title" => $title,
"body" => $msg,
"sound" => "default",
"click_action" => "FCM_PLUGIN_ACTIVITY"//,
"icon" => "fcm_push_icon"
],
"data" => [
"payload" => $payload
],
"to" => $device_token,
"priority" => "high",
"restricted_package_name" => ""
]);

AFTER

$data = json_encode([
"notification" => [
"title" => $title,
"body" => $msg//,
//"sound" => "default",
//"click_action" => "FCM_PLUGIN_ACTIVITY"//,
//"icon" => "fcm_push_icon"
],
"data" => [
"payload" => $payload
],
"to" => $device_token,
"priority" => "high",
"restricted_package_name" => ""
]);

All 4 comments

And if I use plugin cordova-push-notifications, the app is successfully opened after tapping the notification.

Oh well.

What I had to do was to change payload format.
Other suggested removing "notification" entirely and move title and body inside data.
But it caused same issue - tapping not open app - on iOS.

I guess click_action => FCM_PLUGIN_ACTIVITY is causing problem.
To be safe, I removed all others except title and body from notification.

BEFORE

$data = json_encode([
"notification" => [
"title" => $title,
"body" => $msg,
"sound" => "default",
"click_action" => "FCM_PLUGIN_ACTIVITY"//,
"icon" => "fcm_push_icon"
],
"data" => [
"payload" => $payload
],
"to" => $device_token,
"priority" => "high",
"restricted_package_name" => ""
]);

AFTER

$data = json_encode([
"notification" => [
"title" => $title,
"body" => $msg//,
//"sound" => "default",
//"click_action" => "FCM_PLUGIN_ACTIVITY"//,
//"icon" => "fcm_push_icon"
],
"data" => [
"payload" => $payload
],
"to" => $device_token,
"priority" => "high",
"restricted_package_name" => ""
]);

closing as resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rlz picture rlz  ·  4Comments

ghost picture ghost  ·  3Comments

merbin2012 picture merbin2012  ·  4Comments

stephan-nordnes-eriksen picture stephan-nordnes-eriksen  ·  5Comments

Zrnik picture Zrnik  ·  3Comments