当收到来自firebase
的通知时,我使用flatter_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
回调中有这行:FlutterAppBadger.updateBadgeCount(1);
,那么您可以按照本期文章中概述的步骤进行操作:
将此方法添加到Application.kt
FlutterAppBadgerPlugin.registerWith(registry!!.registrarFor("fr.g123k.flutterappbadger"))
[添加]此导入到Application.kt
import fr.g123k.flutterappbadger.FlutterAppBadgerPlugin
源