2

I'm using ShortcutBadger NuGet for alerting number of notification not treated for my app Xamarin.Android. So the implementation is simple :

 ShortcutBadger.ApplyCount(this, _UnreadNotifCount); 

And I've implemented in OnMessageReceived method (I use FireBase notification):

public override void OnMessageReceived(RemoteMessage message)
        {
            ShortcutBadger.ApplyCount(this, 6);

            SendNotification(message.GetNotification().Body, message.Data);
        }

It works fine only in case of opened application and when I receive notification in Closed/Background application mode, it doesn't work!

Do you have any suggestion where/how can I update the badge number for Closed/Background application mode?

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
ali
  • 330
  • 2
  • 13

1 Answers1

2

If your application is in Background or Killed state the best way of updating badge count would be to use the HandleIntent method

In your messaging service class the one that inherits from the following: FirebaseMessagingService

override the handle intent method something like this :

  public override void HandleIntent(Intent p0)
    {
      ShortcutBadger.ApplyCount(this,your_count);
      base.HandleIntent(intent);
    }

Note: that in certain cases this function is also called in foreground notifications that might affect your count.

In case of any issues kindly revert.

Goodluck!

FreakyAli
  • 13,349
  • 3
  • 23
  • 63