Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Add setApplicationIconBadgeNumber action for Android, using ShortcutBadger #624

Closed
wants to merge 1 commit into from

Conversation

barryvdh
Copy link
Contributor

Adds https://github.com/leolin310148/ShortcutBadger support for Android badges, using setApplicationIconBadgeNumber() Fixes #622

Update: Now also handles background notifications

  • Use ShortcutBadger to update badges
  • Implement setApplicationIconBadgeNumber() call directly, similar to iOS (using different thread)
  • Update badge from GCM count property

@barryvdh
Copy link
Contributor Author

Ideally we could add a badge option to the Android init, and then set the badge when possible, so we avoid any BC breaks.

@@ -179,6 +181,20 @@ public void run() {
}
}
});
} else if (SET_APPLICATION_ICON_BADGE_NUMBER.equals(action)) {
Copy link

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?

Copy link
Contributor Author

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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?

Copy link

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

Copy link
Contributor Author

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)

@macdonst macdonst added this to the Release 1.7.0 milestone Mar 14, 2016
@barryvdh
Copy link
Contributor Author

This PR is updated to support both GCM intents + direct setting with setApplicationIconBadgeNumber(). When the count property is set in a GCM message, it should set the badge directly now.

@barryvdh
Copy link
Contributor Author

I have now used a different thread for handling setApplicationIconBadgeNumber() inside the app, similar to other commands.

@macdonst
Copy link
Member

@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.

@barryvdh
Copy link
Contributor Author

Setting the badge works on my HTC M8. It also works with push messages, with one change:
Sending background badge updates (without message/title) doesn't work anymore, because you set the badge number together with creating the notification. So without message/title, the badge will not be updated (not even with content-available).
I don't know if this intentional?

@macdonst
Copy link
Member

@barryvdh ah, good point. I'll make a change and let you know when to re-test.

@macdonst
Copy link
Member

@barryvdh okay, I made the change in the v1.7.x please retest.

@macdonst
Copy link
Member

@barryvdh have you got a chance to re-test the v1.7.x branch?

@barryvdh
Copy link
Contributor Author

Not fully yet, but the way you set the icon didn't really change much since last time I tested..

@macdonst
Copy link
Member

@barryvdh I thought I made the change so that the badge would be set on every incoming message.

@barryvdh
Copy link
Contributor Author

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?
But I'll check soon.

@YaroslavG
Copy link

hi guys,
can I see budge icon on my android version 4.2.2 ?

@macdonst
Copy link
Member

macdonst commented Jun 6, 2016

@barryvdh merged into master now, thanks for the code.

@macdonst macdonst closed this Jun 6, 2016
@macdonst macdonst removed the staging label Jun 6, 2016
@barryvdh barryvdh deleted the shortcutbadger branch June 6, 2016 15:15
@barryvdh
Copy link
Contributor Author

barryvdh commented Jun 6, 2016

Thanks!

@GurubakshSingh
Copy link

Thanks a lot i am new on cordova and working on asus phone and its working. After spending 4 days. Your great

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants