FCM onNotification only works when app is in background

My Ionic 3 app receives notifications via the FCM plugin cordova-plugin-fcm (https://github.com/fechanique/cordova-plugin-fcm). I followed the example on the link, building for Android, testing on an emulator.

Here’s part of my onNotification()

          console.log("Received in background");
        } else {
          console.log("Received in foreground");

The issue is that it ONLY runs when you tap on the notification from the notification drawer while the app is in the background. So if the app is open and a notification arrives, the function doesn’t run. Basically, “Received in foreground” never fires, even when the app is in the foreground. I want “Received in foreground” to log as soon as a notification arrives, even before tapping it.

Any idea how I can accomplish this, please? Or am I missing something.

1 Like

No, I ended up removing FCM and just using Google plugin.

you need to add click-action in you notification data

var message= {
notification: {
title: message.myPhone,
body: message.message,
“click_action”:“FCM_PLUGIN_ACTIVITY”, //Must be present for Android
data: {
account: “Savings”,
balance: “$3020.25”