g123k / flutter_app_badger

Support to update the app badge on the launcher (both for Android and iOS)
https://pub.dev/packages/flutter_app_badger
Apache License 2.0
308 stars 161 forks source link

Unable updateBadgeCount in OnBackgroundMessage #31

Closed JmyW closed 3 years ago

JmyW commented 3 years ago

Hi I'm adopting the latest version 1.1.2. It works in normal implementation on my Android device. But if I add the code into FCM onBackgroundMessage, it generate the error "MissingPluginException(No implementation found for method updateBadgeCount on channel g123k/flutter_app_badger)".

This is different with the issue #13 "https://github.com/g123k/flutter_app_badger/issues/13" I still try the issue #13 is recommended to do "flutter clean", "flutter pub get", of course, not help.

My error is about the plugin is not registered in Android due to the onBackgroundMessage is an isolate code, not depend on the base app. So, I believe there is something should be registered in Application.java. For example, for access SharedPreferences in onBackgroundMessage, we need to add SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")); but I have no idea for app_badge, what should be registerWith? Could you help?

PavlyukovYegor commented 3 years ago

HI @JmyW I got the same issue. But I resolved this issue. I only add this method to Application.kt

FlutterAppBadgerPlugin.registerWith(registry!!.registrarFor("fr.g123k.flutterappbadger"))

and also added this import to Kotlin file

import fr.g123k.flutterappbadger.FlutterAppBadgerPlugin

And it works for me

jenniestrongbow commented 3 years ago

Can you pls show your full application.kt and mainactivity.kt files ? thanks

JmyW commented 3 years ago

@PavlyukovYegor Thank you so much! Yes, it works, now I can change the app badge onBackgroundMessage. Sorry for my late response since my project got serious architecture change. I did full dedication in past 2 weeks. Anyways, thanks again for help. @jenniestrongbow Thanks for asking, Pavlyukov's solution in Application.java solved my problem.

goldenmoon67 commented 1 year ago

hey all. where is the Application.kt file?

JmyW commented 1 year ago

@goldenmoon67 You need to create by yourself with manifest declaration. However the latest version of flutter_app_badge has no longer need this change. You just call it in onBackgroundMessage, it works great!