Android: Updating badge number not working when app is in background or closed state.
See original GitHub issueHi there.
I’ve problem with updating badge number.
on iOS, appIcon badge number automatically updated everytime when I get push notification even the app is in background or closed.
but on Android, appIcon badge number is only changed when app is in foreground and if the app is in background or closed state, I receive fcm push notification but the app badge icon is not automatically changed.
I don’t want to go on with FCM.setBadgeNumber(), because if I call it in javascript code, it will not fired when app is closed or in background and it will not work too.
So is there anyway to update badge number automatically when getting push notification even the app is closed on Android?
Do I need to run kind of background service or task which calls FCM.setBadgeNumber() to achieve this?
iOS is really working well and I want Android should working same as iOS.
My message payload looks like this.
message = { to: 'push token', data: { badge: 3 }, // for Android badge number and only works when app is alive. notification: { title: 'xxx', body: 'xxx', badge: 3 // for iOS badge number and this changes iOS app badge count even app is closed. } };
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:21 (3 by maintainers)
Top GitHub Comments
@shekharskamble I did that and it works only when the app is in foreground. It doesn’t update or show badge count when the app is in killed or background state.
Hi @gitpayal ,
Thanks for the reply. At least the thread is still going 😃 Regarding the payload, we are using the following structure: { “data”: { “title”: “MESSAGE_TITLE”, “body”: “MESSAGE_BODY”, “badge”: “BADGE_COUNT<INT>” } }
In the above JSON, BADGE_COUNT is an integer so while sending the push notification, the actual badge count, for example 5, will be sent. This badge count is the current number that should be shown on the App Icon (or in the list after long-pressing the app icon from Android 8.0 onward)
We are also using Firebase Push Notifications in the application. Everything works well for iOS (payload is different though) but for Android the badge count doesn’t get updated the way it should.
Let me know how you implemented the badge count in your application. It may prove to be helpful.
Regards, AJ