3

I am relatively new to mobile development I am using react native, and i am trying to implement badge notifications for android this is what works on ios:

PushNotificationIOS.setApplicationIconBadgeNumber(count);

I cant seem to find the android equivalent of this I have been referring to this https://github.com/wix/react-native-notifications

It doesnt seem to have anything for badges though Would really appreciate some one pointing me in the right direction

2 Answers 2

2

I SOLVED MY OWN ISSUE: The problem is, you dont manage badge notifications through front end for android like you do with IOS!!! THE SOLUTION: Test on sns if your message is being sent: when you send your push notification through your api your payload should look like this

        ({
              notification: _.assign({ }, payload, {
                body: message,
                message,
                title: payload.MESSAGETITLE
                badge: THIS SHOULD BE AN INT
              })
            })

NOTE is says notification this is a recent FCM update. The int you pass through badge wont matter because it only increments by one, but it has to be an int

2
  • what do you mean by "you don't manage badge notifications through front end for android like you do with IOS"? iOS badge is managed in the payload which is generated at the backend.
    – Zhang Zhan
    Feb 17, 2020 at 0:47
  • sorry i meant badges are handled automatically from the backend and there is no need to set a badge application number like you do for ios, so you dont need a library. I used SNS on AWS to send information to my application... I am sure this is only one of many soltutions, this just happeed to be what i used
    – rabiaasif
    Feb 19, 2020 at 19:29
0

You could use this one https://www.npmjs.com/package/react-native-android-badge

var BadgeAndroid = require('react-native-android-badge');

BadgeAndroid.setBadge(10);
3
  • I've tried this library it doesnt do anything or work...it actually broke my entire app when i installed the node module for it
    – rabiaasif
    Mar 28, 2019 at 13:03
  • What error do you get when u link this library? could you post the stack trace.
    – Bajju
    Mar 29, 2019 at 3:44
  • I got it to compile but now it doesnt do anything if (Platform.OS === 'android') { BadgeAndroid.setBadge(10);} No icon on the application
    – rabiaasif
    Mar 29, 2019 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.