Set badge number on android even if the app is not on background

Hello,

I am currently migrating from the Ionic Push Service to One Signal in order to manage notifications in our app.

The thing is that we are interested in setting the badge number of the app icon to a certain number, which we could do with ionic push service but on One Signal this is only possible on IOS. I have been trying different approaches but i am currenlty a bit lost, the last one was this one:

setupPush(){

   this.oneSignal.startInit('key1', 'key2');

     this.oneSignal.handleNotificationReceived().subscribe(data => {
       console.log('Recieved push notification: ', data);
         //if(data.payload.additionalData){
           this.badge.set(50);
        // }
      

       
     });

     this.oneSignal.handleNotificationOpened().subscribe(data =>{
       console.log('Opened a push notification: ', data);

       let message = data.notification.payload.body;
       let title = data.notification.payload.title;

       let alert = this.alertCtrl.create({
         title: title,
         subTitle: message,
         buttons:[
           {
           text: 'Close',
           role: 'cancel'
         }
       ]
       })

       alert.present();
     });


   this.oneSignal.endInit();
 }

It is just a mock up to start working with notifications. In order to solve the One Signal Android problem with badges i tried to combine handleNotificationOpened() with badge.set(50) using the badge plugin.

The problem is that, this doesn’t work if the app is killed and it is not working on background.

Thanks in advance!!

Hi. According to onesignal appearance doc, https://documentation.onesignal.com/v3.0/docs/appearance#section-badges, badges are automatically set on android.
I am also unable to get it to work, but i am blaming my launcher for it. Look at the note at the bottom of the appearance section - badges only work in certain launchers, so if you are testing in a simulator, it may not work. Have you tried on an actual device? BTW, I have a Moto-X Gen 1 and onesignal badge have not worked so far. :frowning:

1 Like

I have been trying to make it work on a device that i am certain that it supports badges. Anyway i managed to make it work using Firebase Cloud Messaging combined with phonegap push service. In fact it is phonegap the once that is able to do it on android.

I wanted to use OneSignal but as it uses different ids it could get a bit messy so we are using FCM instead of OneSignal.

Anyway, thank you for taking your time to find a solution! :smiley:

Hi Blunder

Can you give more detail on how you made it work? I’m facing the same issue.

Thanks

Leo

Hi, im just wondering if it is possible, did you manage to set a badge number (eg. increase by 1) on the app icon when you get the new push notification? (using phonegap-plugin-push)

Hello Blunder, I am also trying to achieve the same by using FCM combined with push service. Please let us know how you made it to work.
Thank you.