flutter_app_badger
flutter_app_badger copied to clipboard
We can not reset the app badge in some android devices
We are completing a chat app in flutter using this plugin.
Our chat app runs on Firestore.
When there are unread messages, we would like the app to display a badge reminding our users there are messages to check.
Our users would like to see the badge reset to zero and the badge disappears after the messages are all checked.
The first part showing the badge when there are unread messages work well. However, after checking the message, the badge does not reset.
This is our screenplay.
Screenplay - Badge does not reset.
We tried this code:
@override void didChangeAppLifecycleState(AppLifecycleState state) { switch (state) { case AppLifecycleState.resumed: log("MyApp: AppLifecycaeState.resumed"); FlutterAppBadger.removeBadge(); break; case AppLifecycleState.paused: updateMyActiveStatus(false); log("MyApp: AppLifecycleState.paused"); break; case AppLifecycleState.inactive: log("MyApp: AppLifecycleState.inactive"); break; case AppLifecycleState.detached: log("MyApp: AppLifecycleState.detached"); break; default: break; }
Code in pastebin
We also tried this code:
@override void didChangeAppLifecycleState(AppLifecycleState state) { switch (state) { case AppLifecycleState.resumed: log("MyApp: AppLifecycaeState.resumed"); break; case AppLifecycleState.paused: updateMyActiveStatus(false); log("MyApp: AppLifecycleState.paused"); FlutterAppBadger.removeBadge(); break; case AppLifecycleState.inactive: log("MyApp: AppLifecycleState.inactive"); break; case AppLifecycleState.detached: l log("MyApp: AppLifecycleState.detached"); break; default: break; }
or Code in Pastebin
Neither works. Is this our code or an issue with the plugin?
Thanks for your insight.
Android does not offer the same badge display functionality at the OS level as iOS. They are provided at the API level by the manufacturer of the device or launcher application (e.g. MicrosoftLauncher). Basically, Android should not support Badge display and should conform to the specifications of the OS, launcher app, and device.
Incidentally, on Android, you can remove the badge display by writing the following code on the native side at startup and calling it from Flutter. However, this will also remove the notification from the Notification Center.
val notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancelAll()