Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display notification count on app launcher icon in react native?

Is there any way to show icon count on app launcher icon in react native?

I'm using "expo": "29.0.0", "react": "16.3.1", "react-native": "29.0.0"

Like this image

like image 585
Ankush Jain Avatar asked Oct 17 '22 08:10

Ankush Jain


1 Answers

You can try using react-native-firebase, it internally use ShortcutBadger to show notification number badges on Android: https://rnfirebase.io/docs/v5.x.x/notifications/reference/Notifications

The badges in Android is changing at the moment, earlier they were supported only by launchers and since Android 8.0 they are supported also by Android: https://developer.android.com/training/notify-user/badges

So it is a little confusing to understand how react-native-firebase is supporting the badges on Android. But I managed to get them working partly, Android 9.0 device show them and older Android device (Honor8) show them when using

firebase.notifications().setBadge(1) 

but not automatically when notifications are received. I quess the later one is trying to use the old launcher based badge support and either I have not done something correctly or my launcher is not supported by ShortcutBadger. If someone have idea, please share?

If you try using react-native-firebase remember to add ShortcutBadger dependency to android/app/build.gradle and I also added setShowBadge(true) to Notification Channel created (Not sure if it was needed because it was not mentioned in documentation). Otherwise I followed the installation documentation.

like image 172
SinunHenkka Avatar answered Oct 21 '22 00:10

SinunHenkka