How to set Bagde on receiving notification


Stucked in setting badge for app icon on receiving push notification.Using FCM plugin for notification and ionic-native badge plugin for badge.
Trying to set badge count,as per the number of notification received, and to clear the badge when the notification is clicked or the app icon is clicked.

My code:

platform.ready().then(() => {
      var time = setInterval(function(){
          if(data.wasTapped == true){
            alert( JSON.stringify(data) + this.bagde_number);
            alert( JSON.stringify(data) + this.bagde_number);
      }, 2000);

Any Solution is appreciable.



So what is the problem? Using these two plugins sounds like a reasonable idea.


hi @Sujan12,
thanks for the reply.
The problem is that the app badge is not setting while receiving the notification.Now the badge number set only by static method,by specificing the badge number.I need to set the badge number dynamic with the incoming notification and needs to clear the badge from app icon on clicking the app icon or the notification on tapping from the notification tray.

Hope its clear.



Provide a link to the plugins you are using so we can have a look at the docs what is supported.


Links referring for badge, [specified in the code]

Link of fcm plugin,



I see no support for badge numbers here at all.

on the other hand can do what you want:


You only have to call these methods with the values you want to set.
Clearing the badge should also work.


hi @Sujan12,
thanks for the reply,
But I want to set the badge number whenever a notification is received.


If we use this I think the app icon always will have badge with badge number 10,when app is installed, and will increase by one eveytime,and not according to the received number of notifications.

My idea is to display the badge with a badge number equals to the number of received unread notifications. And to clear the badge after reading the notification.

What about using the second link of badge plugin,ie, using cordova.plugins.notification.badge. Any idea to implement the one.

Thanks :slightly_smiling_face:,


Isn’t this what you are doing in your code?

I just mentioned the methods again - I don’t say you should just execute that.

Yes, where is the problem? You code posted above does something like that.

cordova.plugins.notification.badge is the plugin that is used by Ionic Native badge in the background. Ionic Native just gives you nicer code.


[quote=“Sujan12, post:8, topic:105505”]
Yes, where is the problem? You code posted above does something like that.

akhilsanker94: [/quote]
But badge number is not setting to the value,JSON.stringify(data.badge),from the notification.That is the problem for me :expressionless:My notification data has a parameter badge but it cannot be used as a badge number to set the badge.




Can you console.log the data.badge value when you receive the notification?
Can you set a badge number in normal code when clicking a button?


i also have this problem. From what i see all the push plugins(e.g fcm, cordova-plugin-firebase, push-plugin) is not call whenever the notification is received.


Did we manage to get a way around this. Im also using FCM together with the native-badge my problem is that fcm.onNotification only gets called when app is open and not when app is in background.


Hi guys, I think I found a solution.
You can set badge number using push notification that you used such as FCM.
The service need to be handled by push notification service not the badge plugin.
You can refer this link .
After that, maybe you can create a service that can keep track the badge number.