Firebase handle push notification and increase badge

Hi !

I’m using ionic2 with corodva-plugin-fcm to connect on Firebase

I could handle my notifications correctly using this code

FCMPlugin.onNotification((d) => {
    this.badge.increase(1); // not work (don't increase badge) if app in background
    if (d.wasTapped) {
      // Background recieval (Even if app is closed),
      //   bring up the message in UI
    } else {
      // Foreground recieval, update UI or what have you...
    }

  }, function (msg) {
    // No problemo, registered callback
  }, function (err) {
    console.log("Arf, no good mate... " + err);
});

But i can’t increase number of badge, even i tapped on notification
What i want is increase number badge if app in background without clicking on notification

Algorithm example:

If (push notification arrived && app in background) {
  increase badge
}

How can i do that
Thanks

You can send a badge value with the push notification itself. Then you don’t need any code to change this as it is done by the OS.

Thanks @Sujan12 for your answer,
Unfortunately i didn’t found any parameter for Android to send a value of my badge

The badge option is available only for iOS
https://firebase.google.com/docs/cloud-messaging/http-server-ref#send-downstream

Is there any solution ?
Thanks,

I don’t think badge numbers exist in Android at all or are at least not used in that way, right?

No it’s exist for Android,
I could add a badge number or increase it, but only if i’m on foreground of my App,
i used:

this.badge.increase(1);

yes it seems badge numbers are not exist in that way by sending its value with notification

Thanks,

No, I meant in general: badge numbers are not used to indicate the number of push notificaitons received for apps on Android.

Yes i think it’s that,

Out of curiosity what’s the utility of badge numbers on Android ?

The next version of Android, Android 0, will copy that feature from iOS:
https://developer.android.com/preview/features/notification-badges.html

Here the current situation is described:

It will be useful i’m sure :slight_smile:

Thanks @Sujan12 to share