Custom badge with number for app icon is not showing for Android devices - working for iOS device

Sagar S 21 Reputation points
2021-07-13T11:01:30.423+00:00

Trying to show a custom badge on app icon based on some data in the app. I am using xamarin forms for both Android and iOS apps.
The logic and code is working fine for iOS but not for Android. Tried various suggestions, dependency services and plugin but on Android it is not working.
One thing to note is that the badge is showing in case of Push Notifications but if we want to show some custom badge at all times on App icon. that is not working.

Below is the source code for custom badge showing on iOS. Can someone guide me on how can I achieve the same result on Android.
public void SetBadge(int number)
{​​​​​​​
try
{​​​​​​​
var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.ApplicationIconBadgeNumber = number;
}​​​​​​​
catch (Exception ex)
{​​​​​​​
Crashes.TrackError(ex);
}​​​​​​​
}​​​​​​​

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-07-14T03:10:57.767+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Unfortunately, Android does not allow changing of the application icon because it's sealed in the APK once the program is compiled. There is no way to programmatically change it to a 'drawable'.

    You may achieve your goal by using a widget instead of an icon. Widgets are highly customizable and can do what you want. Please see this thread.

    Here is similar thread about how to achieve the Custom badge with number for app icon in Xamarin. It contains several ways to achieve it, you can try it.

    https://social.msdn.microsoft.com/Forums/en-US/6f13d52c-8b6d-4160-9530-20b5e0a60f53/how-to-show-badge-count-on-app-icon-in-xamarin-crossplotform-application-for-both-android-and-ios?forum=xamarinios

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.