Ionic1, display badge count when push notification arrives


#1

i am working with ionic 1 app and implemented push notifications in it. Now i am trying to implement badge on app icon and for that purpose i am using cordova plugin which is (Cordova Badge Plugin ). it is working when push notifications arrives and by clicking on that notification it opens the app and i have implemented badge logic there. i code it like this.

$rootScope.$on(‘cloud:push:notification’, function (event, data) {
document.addEvenLtistener(‘deviceready’, function () {
cordova.plugins.notification.badge.requestPermission(function (granted) {
cordova.plugins.notification.badge.set(10);
});
}, false);
var msg = data.message;
alert(msg.title + ': ’ + msg.text);
});

on closing app it shows badge and when i open app again it clears the badge so i know how actually badge is working. To clear badge i am doing code like this.

        document.addEventListener('deviceready', function () {
             cordova.plugins.notification.badge.clear();
        }, false);

All i want is to app icon to display the badge count when the notification arrives, right now it shows the count but only when i open the app.


#2

This would be some logic that is executed by the OS as your app is not even activated when a push notification is received and displayed by the OS. For iOS I think it is a parameter of the push notification payload that has to be set, so I would look into the documentation of the push provider or plugin you use.


#3

if you see https://ionicframework.com/docs/native/push/ this plugin it do contains badge attribute for ios but there is no attribute for android