react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

Updating AppIconBadgeCount when app is not active (#android)

Open manjeet-dobble opened this issue 10 years ago • 20 comments

Is there a way to update applicationBadgeIconCount when app is not active (neither in foreground nor in background)

manjeet-dobble avatar Oct 12 '16 08:10 manjeet-dobble

With iOS you can send a push notification and set the application badge number in there.

With Android, you will be able to once the current master is released. It make it possible to run code when a push notification is received even if your app isn't running.

npomfret avatar Oct 12 '16 13:10 npomfret

Thanks will be waiting for that nice update

manjeet-dobble avatar Oct 13 '16 06:10 manjeet-dobble

Any progress?

klinkov avatar Dec 06 '16 15:12 klinkov

I believe this is supported, on both iOS and Android. Can we close?

npomfret avatar Dec 07 '16 23:12 npomfret

Can you post gist with code example, pls?

klinkov avatar Dec 07 '16 23:12 klinkov

Just follow the docs... PushNotification.setApplicationIconBadgeNumber

npomfret avatar Dec 08 '16 00:12 npomfret

Work on iOS, not on Android

    "react": "15.4.1",
    "react-native": "0.38.0",
    "react-native-push-notification": "2.2.1",

Test code

function resetBadge() {
    AsyncStorage.setItem('pendingNotifications', JSON.stringify([]));
    PushNotification.setApplicationIconBadgeNumber(10);
    console.log('BADGE RESET');
}

klinkov avatar Dec 08 '16 00:12 klinkov

Do you see an exception in logcat? It doesn't work on all android devices.

npomfret avatar Dec 08 '16 00:12 npomfret

Android device 4.4.2 - dont work There is no exception in logicat

klinkov avatar Dec 08 '16 00:12 klinkov

Android 6.0.0 emulator - dont work iOS 9 emulator - work iOS 10 emulator - work

klinkov avatar Dec 08 '16 00:12 klinkov

It's likely that it won't work at all on an emulator (though I'm not 100% sure on that). Try it on a physical device.

Also, make sure you're not filtering out the exception in logcat by accident.

npomfret avatar Dec 08 '16 01:12 npomfret

Did't work with stock Android or MIUI on real devices. Cant you write devices / launcher where it work?

klinkov avatar Dec 08 '16 12:12 klinkov

working fine,

manjeet-dobble avatar Dec 08 '16 13:12 manjeet-dobble

@manjeet-dobble can you provide code example and your react, react-native, react-native-push-notification version and Android device + version info, pls?

klinkov avatar Dec 08 '16 14:12 klinkov

@klinkov actually my code is almost same as yours, but I am unable to update its count dynamically

manjeet-dobble avatar Dec 08 '16 14:12 manjeet-dobble

What about other, android, device and packages versions?

klinkov avatar Dec 08 '16 14:12 klinkov

Cannot get this working on any android device. RN 0.39, plugin version 2.2.1

JonoH avatar Feb 17 '17 09:02 JonoH

Ok can get it working but only while the app is in the foreground. Number doesn't change when app is in the background or closed on Android.

JonoH avatar Feb 17 '17 16:02 JonoH

Also looking for a solution to this. On iOS a scheduled notification without message is the way to do it, but I get an error when sending null as message here. No idea how it's usually done on Android.

I would actually prefer a separate method for it - how about introducing a scheduleApplicationIconBadgeNumberUpdate that takes a time and number?

robertherber avatar Feb 22 '17 07:02 robertherber

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Apr 30 '20 00:04 github-actions[bot]