katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.56k stars 1.74k forks source link

Local notifications with badge #1745

Open stefanwilliam96 opened 5 years ago

stefanwilliam96 commented 5 years ago

can local notification automatically generate badge in apps icon ?

fakir22 commented 5 years ago

As seen on the documentation, there is a 'badge' property for notification object.

Property Badge Type Number Description The number currently set as the badge of the app icon in Springboard (iOS) or at the right-hand side of the local notification (Android) - Default: 0 (which means don't show a number)

So I think you could use something like this :

// Set your desired value here or increment it from previous actions
var badgeNum = 1; 

// Change some default values here
cordova.plugins.notification.local.setDefaults({
    badge: badgeNum
});

I didn't try it but it should work. Hope it helps !

stefanwilliam96 commented 5 years ago

As seen on the documentation, there is a 'badge' property for notification object.

Property Badge Type Number Description The number currently set as the badge of the app icon in Springboard (iOS) or at the right-hand side of the local notification (Android) - Default: 0 (which means don't show a number)

So I think you could use something like this :

// Set your desired value here or increment it from previous actions
var badgeNum = 1; 

// Change some default values here
cordova.plugins.notification.local.setDefaults({
    badge: badgeNum
});

I didn't try it but it should work. Hope it helps !

the problem is, this local notification plugin using badge plugin which didnt worked :v

fakir22 commented 5 years ago

@Katzer is also the creator of the badge plugin and said the following on this issue (https://github.com/katzer/cordova-plugin-badge/issues/124)

Please notice that the plugin only supports devices that are supported by ShortcutBadger. There's no error if its not possible to set a badge. The cordova plugin nor the underlying ShortcutBadger cannot know if its working or not because its not a core Android API.

I don't know where the problem come from but you could start by using the "IsBageWorking" tool provided on ShortcutBadger page : https://github.com/leolin310148/ShortcutBadger#isbadgeworking

A tool for displaying your device, launcher & android version and testing whether ShortcutBadger works or not may.

stefanwilliam96 commented 5 years ago

@katzer is also the creator of the badge plugin and said the following on this issue (katzer/cordova-plugin-badge#124)

Please notice that the plugin only supports devices that are supported by ShortcutBadger. There's no error if its not possible to set a badge. The cordova plugin nor the underlying ShortcutBadger cannot know if its working or not because its not a core Android API.

I don't know where the problem come from but you could start by using the "IsBageWorking" tool provided on ShortcutBadger page : https://github.com/leolin310148/ShortcutBadger#isbadgeworking

A tool for displaying your device, launcher & android version and testing whether ShortcutBadger works or not may.

yeah i know, i already try his badge plugin but didnt work for me lol xD anyway thanks for your answer