封闭/背景应用模式下的FCM更新徽章编号 [英] FCM Update BadgeNumber in Closed/Background Application Mode
问题描述
我正在使用 ShortcutBadger NuGet来提醒未针对我的应用程序处理的通知数量 Xamarin.Android .因此实现很简单:
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);
并且我已经在OnMessageReceived方法中实现了(我使用FireBase通知):
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?
推荐答案
如果您的应用程序处于后台"或已终止"状态,则更新徽章计数的最佳方法是使用HandleIntent方法
If your application is in Background or Killed state the best way of updating badge count would be to use the HandleIntent method
在您的消息传递服务类中,该类继承自以下内容:FirebaseMessagingService
In your messaging service class the one that inherits from the following: FirebaseMessagingService
重写类似这样的handle intent方法:
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.
祝你好运!
这篇关于封闭/背景应用模式下的FCM更新徽章编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!