expo: Notifications.setBadgeCountAsync(0); Does not work on Android

Summary

Notifications.setBadgeCountAsync(0); Does not work on Android.

Also when the badge number is sent with the expo notification to the android device, the badge number gets added to the current badge number instead of overriding the badge number like the ios functionality.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

41

Environment

Expo CLI 4.4.3 environment info: System: OS: macOS 10.15.7 Shell: 3.2.57 - /bin/bash Binaries: Node: 10.16.3 - /usr/local/bin/node npm: 6.14.5 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: API Levels: 25, 26 Build Tools: 23.0.1, 23.0.3, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.1, 27.0.3 System Images: android-25 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom IDEs: Android Studio: 3.0 AI-171.4443003 Xcode: 11.5/11E608c - /usr/bin/xcodebuild npmPackages: expo: ^41.0.0 => 41.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 react-navigation: ^4.4.0 => 4.4.4 npmGlobalPackages: expo-cli: 4.4.3 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

Use Notifications.setBadgeCountAsync(0); in the Android app.

Also, try sending a badge # in the Expo notification. The badge number is added rather than overrwritten.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 30 (5 by maintainers)

Most upvoted comments

I never solved it myself. I ended up removing the set badge functionality all together. I am not sure how it hasnt been fixed after being a bug for 2 years now.

yeah, I’m just trying to clear the badges entirely, I may just bring in another package to do it for now. Push notifs are integral to my use case so getting rid of them altogether isn’t an option

I am still using push notifications but I am not setting any badge count when I send the notification. I would really like to be able to do this but obviously need a way to clear the badge count for this.

I’m running into this problem as well. what gives with the lack of response here? This issue needs to be reopened

Expo 48 Galaxy S21 Android 13 expo-notifications 0.18.1

I got this to work using Notifications.dismissAllNotificationsAsync() for android. So the overall code I used was this:

useEffect(() => {
  const subscription = AppState.addEventListener('change', (nextAppState) => {
    if (nextAppState === 'active') {
      if (Platform.OS === 'ios') {
        Notifications.setBadgeCountAsync(0);
      } else if (Platform.OS === 'android') {
        Notifications.dismissAllNotificationsAsync()
      }
    }
  });

  return () => {
    subscription.remove();
  };
}, []);

I’m doing local notifications using expo-notifications, not sure if it will work for push notifications. Hope it helps.

I never solved it myself. I ended up removing the set badge functionality all together. I am not sure how it hasnt been fixed after being a bug for 2 years now.

@mikeRChambers610 - it was closed automatically because there was no activity for several months and nobody responded when prompted about it being closed. can you open a new issue with a minimal reproducible example? we’re a small team and trying to stay up on top of everything and the best ways to get help are:

  • create a good issue with reproducible example repo we can clone and run and reproduce
  • investigate the root cause and share your findings
  • send a pr with a proposed fix

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

how interesting… if the maintainer doesn’t respond, every ticket will be closed 7 days after stale. a perfect way to keep the issue number down. seems too aggressive.

I’m also running into this issue. Seems like the only way to clear the badge count on Android is to tap or clear any pending push notifications through the Android OS itself. setBadgeCountAsync has no effect. This is on Android 12.

I am having the same problem. Did someone manage to solve it ?