AppIcon Badge with .NET MAUI

AppIcon Badge with .NET MAUI

01 December 2022

.NET MAUI/Xamarin

Buy Me A Coffee

Winter is coming!

This article is a continuation of a series of potential Essentials APIs, that can be added to .NET MAUI later. It is devoted to the AppIcon badge. If your app sends notifications or you want the user to pay attention to the app, this API is what you need.

As usual, starting from creating the interface:

We need only 1 method that sets badge count. If the count is 0 or less, the badge is removed.

Android

In Android, icons are displayed in the launcher, and there are a lot of different launchers. Each of them requires its own permissions and implementations. I recommend installing the next NuGet package:

Add the next permissions to AndroidManifest.xml:

And finally, implement our interface:

Android

iOS/MacCatalyst

Apple's implementation is much simpler:

You request NotificationCenter permission to update the badge. After that, you can update the Badge number.

iOS/MacCatalyst

Windows

Windows doesn't require any permissions or additional packages:

Windows

Tizen

And last, but not least. Tizen has its own control to work with badges - BadgeControl.

But first, you need to set permission in tizen-manifest.xml:

Then implement our interface:

Tizen doesn't allow adding multiple badges to the same application, so you also need to check if the badge already exists and update it.

Tizen

Result

Now we can call our API and see the result:

The final code can be found on GitHub.

Happy coding!

Buy Me A Coffee

Related:

Creating a bottom sheet using .NET MAUI

Creating a bottom sheet using native dialogs.

Replicate a bank application UI using .NET MAUI

Replicate the Ukrainian Monobank application UI using .NET MAUI.

An unhandled error has occurred. Reload

🗙