☂️ Support app badges on more platforms
- docs: the readme points to a deprecated package and says that this plugin cannot provide bags numbers when it in fact can on Android and iOS
- Windows: https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.badgeupdatemanager?view=winrt-26100
- Linux: Doesn't seem to be standardized (see my comment here)
- Web: See #2466 and the MDN docs
Could you maybe give a small example on how you implemented the badge numbers on Android & iOS?
Sure (note, I didn't write the Android and iOS implementations):
Android
- set your
AndroidNotificationDetails.numberto a non-null integer - the native plugin then uses these lines to add the badge
https://github.com/MaikuB/flutter_local_notifications/blob/4ef55a243a9c349f943c64029b3362350f4cabfa/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L417-L419
iOS/MacOS
- set your
DarwinInitializationSettings.requestBadgePermissionto true - set your
DarwinNotificationDetails.badgeNumberto a non-null integer - the native plugin then uses these lines to add the badge
https://github.com/MaikuB/flutter_local_notifications/blob/4ef55a243a9c349f943c64029b3362350f4cabfa/flutter_local_notifications/ios/Classes/FlutterLocalNotificationsPlugin.m#L620-L622
docs: the readme points to a deprecated package and says that this plugin cannot provide bags numbers when it in fact can on Android and iOS
Although a typical use case is to have it tied to notifications, note that what is mentioned in the docs was specifically referring to app badging that can also be done without notifications. This is why I mentioned "directly"
On Android, this refers to how there's no official Android API for this at an app level. If you looked into the discontinued plugin, it makes use of a popular library in the Android ecosystem where there are various launchers that allow seeing and setting the badge count. This looks different to what can be seen on stock Android where there isn't a number in the corner of the app icon. I use to have a Sony phone where I noticed badge numbers but this was prior to working on this plugin. I don't know if it'll respect what's passed through the notification. Might need to get help from others and also check other phones that I can borrow to confirm.
On iOS/macOS, this was referring to https://developer.apple.com/documentation/uikit/uiapplication/applicationiconbadgenumber. It wasn't deprecated at the time and looks like it's only been recently been considered as deprecated with the docs mentioning to use this instead
If you looked into the discontinued plugin, it makes use of a popular library in the Android ecosystem where there are various launchers that allow seeing and setting the badge count.
...Interesting. I didn't even think to go the Linux way of "better support every combo that exists" and thought the base Android sdk would be enough. I think it's reasonable that badges without a notification aren't implemented yet, and if we do find a replacement, we can always add it to the Android plugin.
Still, probably worth clarifying the distinction in the docs. I have a PR for that but so far I've only done the native setup docs, not the list of features the plugin supports