The README instructions say that to work with background messages on android, we need to extend FlutterApplication:
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
But since the v2 embedding update, GeneratedPluginRegistrant.registerWith expects a flutterEngine instead of a pluginRegistry. So the code doesn't compile. I can't even simply omit the registration for the background thread because i need to use some plugins in the backgroundView
So i'm currently manually writing all the plugin registration code to get things working:
override fun registerWith(registry: PluginRegistry) {
PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"))
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
FlutterLocalNotificationsPlugin.registerWith(registry.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"))
FlutterSecureStoragePlugin.registerWith(registry.registrarFor("com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin"))
SqflitePlugin.registerWith(registry.registrarFor("com.tekartik.sqflite.SqflitePlugin"))
}
Also, the v2 embedding upgrade guide says:
Remove the reference to
FlutterApplicationfrom the application tag.
So is overriding FlutterApplication even recommended anymore? What's the best way to configure FlutterFirebaseMessagingService?
The example app does not show usage of onBackgroundMessage either. so it's not clear what the right way is.
Here is sample project https://github.com/hw-dwalter/flutter-firebase-messaging-background-example and video https://youtu.be/frhnHX8Z-UQ demonstrating the bug.
So ist there currently no way to use background messages when using v2 embedding?
In my case the GeneratedPluginRegistrant looks like this:
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.registerWith(shimPluginRegistry.registrarFor("flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin"));
io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.firebaseauth.FirebaseAuthPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.core.FirebaseCorePlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
flutterEngine.getPlugins().add(new com.baseflow.permissionhandler.PermissionHandlerPlugin());
flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
In the example project from https://github.com/FirebaseExtended/flutterfire/issues/2183#issuecomment-601077375 there is no other olugin code that might need flutterEngine.
@hw-dwalter Have you managed to make onBackgroundMessage to work?
They need to update the tutorial on pub.dev, as they are upgrading to Android V2 but I did SEVERAL tests and it seemed like a very bad transition. It is not working, so it is necessary to improvise and be content with the use of only 1 package in the background. I hope they soon update the README - Getting Started from pub.dev to Android v2 embedding.
Has anyone successfully handle on backgroud notification with OnBackgroundMessage?
@Ehesp should this be closed as a duplicate of https://github.com/FirebaseExtended/flutterfire/issues/1775?
I solved this issue
https://github.com/FirebaseExtended/flutterfire/issues/2777#issuecomment-685805903