ApplicationIcon Badge Number

Starting with 8.0 (API level 26), notification badges (also known as notification dots) appear on a launcher icon when the associated app has an active notification. Users can long-press on the app icon to reveal the notifications. As shown in image below:

 

These dots appear by default in launcher apps that support them and there's nothing your app needs to do. However, there might be situations in which you don't want the to notification dot to appear or you want to control exactly which notifications to appear there.

Disable badging

There are cases where badges don't make sense for your notifications, so you can disable them on a per-channel basis by calling SetShowBadge(false) on your AN_NotificationChannel object.

For example, you might want to disable notification badges in the following situations:

  • Ongoing notifications: Most ongoing notifications, such as image processing, media playback controls, or current navigation instructions, don't make sense as a badge.
  • Calendar reminders: Avoid badging events occurring at the current time.
  • Clock or alarm events: Avoid badging notifications related to current alarms.

The following sample code illustrates how to hide badges for a notification channel:

using SA.Android.App;
...

var channelId = "my_channel_id";
var name = "My Channel Name";
var description = "My Channel Description";
var importance = AN_NotificationManager.Importance.DEFAULT;

AN_NotificationChannel channel = new AN_NotificationChannel(channelId, name, importance);
channel.Description = description;
channel.SetShowBadge(false);

// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
AN_NotificationManager.CreateNotificationChannel(channel);

Set custom notification count

By default, each notification increments a number displayed on the long- press menu (visible in figure 1), but you can override this number for your app. For example, this might be useful if you're using just one notification to represent multiple new messages but you want the count here to represent the number of total new messages.

To set a custom number, call setNumber() on the notification, as shown here:

using SA.Android.App;
...

var channelId = "my_channel_id";
var builder = new AN_NotificationCompat.Builder();
builder.SetChanelId(channelId);
builder.SetContentTitle("New Messages");
builder.SetContentText("You've received 3 new messages.");
builder.SetSmallIcon("custom_icon");
builder.SetNumber(messageCount);

var notification = builder.Build();

Modify a notification's long-press menu icon

The long-press menu displays the large or small icon associated with a notification if available.

By default, the system displays a large icon, but you can call AN_NotificationCompat.Builder.setBadgeIconType() and pass in the BADGE_ICON_SMALL constant to display the small icon.

using SA.Android.App;
...

var channelId = "my_channel_id";
var builder = new AN_NotificationCompat.Builder();
builder.SetChanelId(channelId);
builder.SetContentTitle("New Messages");
builder.SetContentText("You've received 3 new messages.");
builder.SetSmallIcon("custom_icon");
builder.SetBadgeIconType(AN_NotificationCompat.BADGE_ICON_SMALL);

var notification = builder.Build();