vadimrostok
vadimrostok

Reputation: 131

The onNotification callback doesn't fire if an app is in background. Using cordova-plugin-fcm-with-dependecy-updated cordova plugin

The onNotification callback doesn't fire after tapping on a notification while the app is in background. The app goes to the foreground, but the JS event handler does not execute. Also, in the case of Android, there are no messages containing FCMPluginActivity in Logcat, therefore I think that the corresponding activity does not start.

Since we use meteor, Cordova version is fixed by Meteor version, and the newest meteor version has cordova-android v7.1.4 and cordova-ios v4.5.5, failing the requirements to use the latest version of cordova-plugin-fcm-with-dependecy-updated. So we use version 3.2.0.

How to reproduce (in case of Android):

  1. Create new meteor app: meteor create --full ./test-fcm.
  2. Add the plugin: meteor add cordova:[email protected].
  3. Add mobile-config.js file to the root, containing App.info({id: "com.yourCompany.appId"});.
  4. Add google-services.json file to test-fcm/cordova-build-override/platforms/android/app/.
  5. Start the app: meteor run android.
  6. Connect Chrome DevTools to emulator and create onNotification event handler: window.FCMPlugin.onNotification((data) => { console.log(data); });.
  7. Send notification with custom data from the firebase console.

Any advice will help. Thanks!

Upvotes: 1

Views: 431

Answers (1)

vadimrostok
vadimrostok

Reputation: 131

Turns out we forgot to add click_action field to the FCM request payload ("click_action":"FCM_PLUGIN_ACTIVITY").

With this field in place onNotification works correctly.

Upvotes: 2

Related Questions