【问题标题】:Add badge on icon launcher when receiving notification from firebase cloud messaging flutter收到来自 Firebase 云消息颤动的通知时,在图标启动器上添加徽章
【发布时间】:2021-09-28 16:52:54
【问题描述】:

当收到来自firebase 的通知时,我正在使用flutter_app_badger 包在图标启动器上添加一个徽章。但它只适用于onMessage。有什么解决办法吗?谢谢。

我的代码:

    fcm.configure(
  
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
FlutterAppBadger.updateBadgeCount(1);


},
  onBackgroundMessage: myBackgroundMessageHandler,
  onLaunch: (Map<String, dynamic> message) async {
    print("onLaunch: $message");
    FlutterAppBadger.removeBadge();
  },
  onResume: (Map<String, dynamic> message) async {
    print("onResume: $message");
  },
);

【问题讨论】:

  • 请发myBackgroundMessageHandler的代码。

标签: firebase flutter notifications firebase-cloud-messaging badge


【解决方案1】:

假设您在myBackgroundMessageHandler 回调中有这一行:FlutterAppBadger.updateBadgeCount(1);,那么您可以按照此issue 中的步骤概述:

  1. 将此方法添加到Application.kt

    FlutterAppBadgerPlugin.registerWith(registry!!.registrarFor("fr.g123k.flutterappbadger"))
    
  2. [添加]此导入到 Application.kt

    import fr.g123k.flutterappbadger.FlutterAppBadgerPlugin
    

Source

【讨论】:

  • 抱歉回复晚了,在 myBackgroundMessageHandler 回调中就像你的假设一样。谢谢你的回答,我会听从你的建议,如果它有效,我会告诉你。欣赏它。 @Victor Eronmosele
猜你喜欢
  • 2017-06-30
  • 2014-12-31
  • 2018-09-05
  • 2013-08-26
  • 2022-11-10
  • 1970-01-01
  • 2017-05-05
  • 2017-09-04
  • 1970-01-01
相关资源
最近更新 更多