-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add setApplicationIconBadgeNumber action for Android, using ShortcutBadger #624
Conversation
Ideally we could add a |
@@ -179,6 +181,20 @@ public void run() { | |||
} | |||
} | |||
}); | |||
} else if (SET_APPLICATION_ICON_BADGE_NUMBER.equals(action)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this code only runs when the app is opened, not when the push message arrives (That's what happens on my Device, anyway). If this is indeed the case, it can't update the counter badge until the app opened, which doesn't solve the bug - no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fully no, that's what I said, not really sure how. But with content available, you could still update in background.
But for background, this could work similarly right? Not sure how to fix it otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've solved it in this branch:
https://github.com/silo-co/phonegap-plugin-push
You can read about it here:
http://www.yossale.com/Ionic-android-icon-badges/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so your patch (master...silo-co:master) handles the updating of the push in the background, and mine in foreground for setApplicationIconBadgeNumber
right?
So we can combine both methods, right? Can you submit a PR to my branch to add that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to merge them - the code I wrote handles both cases, because it's called anyway. I'm not sure that handling the same issue from different places in the code is wise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No the first method happened only when you called setApplicationIconBadgeNumber()
directly, right?
I've abstracted it to a public static function in the PushPlugin class, and added it to be called when a count
it available. Similar to your branch, but when it's null
, it doesn't change.
Also, you can call it directly (eg. without push, but with setApplicationIconBadgeNumber()
directly)
This PR is updated to support both GCM intents + direct setting with |
I have now used a different thread for handling |
5a604c9
to
3a837f9
Compare
3a837f9
to
3b271fb
Compare
3b271fb
to
f9f3336
Compare
@barryvdh can you please retest by using the 1.7.x branch of the plugin? I don't actually have any phones that support badging. I've tested on a OnePlusOne and Nexus 5 with no ill affects. |
Setting the badge works on my HTC M8. It also works with push messages, with one change: |
@barryvdh ah, good point. I'll make a change and let you know when to re-test. |
@barryvdh okay, I made the change in the v1.7.x please retest. |
@barryvdh have you got a chance to re-test the v1.7.x branch? |
Not fully yet, but the way you set the icon didn't really change much since last time I tested.. |
@barryvdh I thought I made the change so that the badge would be set on every incoming message. |
Yeah I meant that you didn't change the way you actually called the badger plugin, just the logic for parsing the message etc. So even if you didn't test it actually sets the badge, you can verify the logic, right? |
hi guys, |
@barryvdh merged into master now, thanks for the code. |
Thanks! |
Thanks a lot i am new on cordova and working on asus phone and its working. After spending 4 days. Your great |
This thread has been automatically locked. |
Adds https://github.com/leolin310148/ShortcutBadger support for Android badges, using
setApplicationIconBadgeNumber()
Fixes #622Update: Now also handles background notifications
setApplicationIconBadgeNumber()
call directly, similar to iOS (using different thread)count
property