android - FCM 在封闭/后台应用程序模式下更新 BadgeNumber

标签 android firebase xamarin xamarin.android firebase-cloud-messaging

我正在使用ShortcutBadger NuGet 用于提醒未针对我的应用 Xamarin.Android 处理的通知数量。所以实现很简单:

 ShortcutBadger.ApplyCount(this, _UnreadNotifCount); 

我已经在 OnMessageReceived 方法中实现了(我使用 FireBase 通知):

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

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

它仅在打开应用程序的情况下工作正常,当我在关闭/后台应用程序模式下收到通知时,它不起作用!

您对在哪里/如何更新封闭/后台应用程序模式的徽章号码有什么建议吗?

最佳答案

如果您的应用程序处于后台或终止状态,更新徽章计数的最佳方法是使用 HandleIntent 方法

在您的消息传递服务类中,继承自以下内容的类:FirebaseMessagingService

重写句柄 Intent 方法,如下所示:

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

注意:在某些情况下,前台通知中也会调用此函数,这可能会影响您的计数。

如有任何问题,请回复。

祝你好运!

关于android - FCM 在封闭/后台应用程序模式下更新 BadgeNumber,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49997519/

相关文章:

php - 纬度经度脚本给出 MySQL 错误 "You have an error in your SQL syntax; ... for the right syntax to use near ' long”

javascript - 使用 FCM 在前台为浏览器中的每个选项卡接收一个通知

swift - 在展开可选值时意外发现 nil(firebase,swift)

java - 如何使用 Firebase 结果检索 ListView 中的位置

xamarin - 在 Fabulous (F#) UWP 应用中使用 Xamarin Essentials 文件选取器

c# - 如何在 Xamarin Picker 控件中显示字符串和图像两个项目?

android - 用对话框覆盖后退按钮

android - 以编程方式将位置分配给android中的按钮

android - sc 启动 intelhaxm 错误 [SC] startservice failed 31 : a device attached to the system is not functioning

c# - 如何在没有 IDE 的情况下使用 Xamarin?