jhen0409 / react-native-android-badge

A react native wrapper for leolin310148/ShortcutBadger.
MIT License
90 stars 36 forks source link

Badge count number reverts to previous value only if you set it to zero #20

Open gabeDevlift opened 3 years ago

gabeDevlift commented 3 years ago

I originally had a badge number of 2. I used BadgeAndroid.setBadge(15); in my code, and it worked. However, when I tried BadgeAndroid.setBadge(0);, the badge number reverted to 2.

Does anyone know why this might be? Is there any other info I can provide?

Froncz commented 3 years ago

@gabeDevlift have you managed to fix the issue?

osvald0 commented 2 years ago

I have the same problem. It looks like the repository is abandoned :(

Froncz commented 2 years ago

@osvald0, I've managed to handle the issue by switching to https://github.com/zo0r/react-native-push-notification

And using:

import RNPushNotification from 'react-native-push-notification';

RNPushNotification.setApplicationIconBadgeNumber(unreadNotificationCount);

It worked fine for both Android and iOS.

Froncz commented 2 years ago

@osvald0, actually, that might not be the full solution. In android, the notifications stay in a tray and that was the actual reason for getting the badge number reverted. To get rid of the notifications you need to cancel them:

RNPushNotification.cancelAllLocalNotifications();
osvald0 commented 2 years ago

Yes, cancelAllLocalNotifications works fine. Thanks @Froncz !

andresliu-mks commented 2 years ago

@osvald0 @Froncz Did you try this on an emulator or a physical Android device? Can you share on which model or specifications you managed to display the notifications badge?

osvald0 commented 2 years ago

@andresliu-mks physical device, Samsung A30 and Samsung A52.

andresliu-mks commented 2 years ago

@andresliu-mks physical device, Samsung A30 and Samsung A52.

Thank you. Did you just follow the setup and usage instructions and it worked? I can't seem to get this library working on any device @osvald0

andresliu-mks commented 2 years ago

Okay, so I found out that the badge would appear with the number you set only after receiving a push notification (I only tested this with remote, not local ones)

4D616B6572 commented 2 years ago

@Froncz thanks for sharing, but it seems like it's not functional on android emulator? or is there anyone have any idea to deal with this problem? @andresliu-mks