Hi,
Can someone from the support team please fix the read me/example on pub.dev?
https://pub.dev/packages/firebase_messaging
I have followed the exact steps to add firebase messaging to a newly created project. When I do as suggested on the link above
- Add an Application.java class to your app in the same directory as your MainActivity.java. This is typically found in
/android/app/src/main/java/ /.
and I am getting errors like:
error: cannot access FirebaseMessagingService
FlutterFirebaseMessagingService.setPluginRegistrant(this);
^
The github example app is doing something completely different. Can someone please have a single version for howto use this plugin? Not sure if the example project is the new version or the one on pub.dev!
Thanks!
Please someone who successfully installed fcm let us knw what we should do exactly :/
Can someone please bump up the priority of this issue?
The plugin is not usable for anyone trying to add it to their project, so this not only a documentation issue. For all practical purposes, anyone trying to integrate firebase_messaging into their project now, can't do it!
the same issue with me can anyone help
Add this class :
public class FirebaseCloudMessagingPluginRegistrant {
public static void registerWith(PluginRegistry registry) {
if (alreadyRegisteredWith(registry)) {
return;
}
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
final String key = FirebaseCloudMessagingPluginRegistrant.class.getCanonicalName();
if (registry.hasPlugin(key)) {
return true;
}
registry.registrarFor(key);
return false;
}
}
and call it in Application like
public class App extends FlutterApplication implements PluginRegistrantCallback {
public void onCreate() {
super.onCreate();
// Stetho.initializeWithDefaults(this);
FlutterFirebaseMessagingService.setPluginRegistrant(this);
FlutterMain.startInitialization(this);
NeverCrash.init(new NeverCrash.CrashHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
FileUtils.writeToFile(App.this, "bug " + System.currentTimeMillis(), Log.getStackTraceString(e));
}
});
}
@Override
public void registerWith(PluginRegistry registry) {
FirebaseCloudMessagingPluginRegistrant.registerWith(registry);
}
}
dont forget to add name=".App" in the manifest file.
@a-elhaddad Thanks. Could you add imports to the code?
Add this class :
public class FirebaseCloudMessagingPluginRegistrant { public static void registerWith(PluginRegistry registry) { if (alreadyRegisteredWith(registry)) { return; } FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")); } private static boolean alreadyRegisteredWith(PluginRegistry registry) { final String key = FirebaseCloudMessagingPluginRegistrant.class.getCanonicalName(); if (registry.hasPlugin(key)) { return true; } registry.registrarFor(key); return false; } }and call it in Application like
public class App extends FlutterApplication implements PluginRegistrantCallback { public void onCreate() { super.onCreate(); // Stetho.initializeWithDefaults(this); FlutterFirebaseMessagingService.setPluginRegistrant(this); FlutterMain.startInitialization(this); NeverCrash.init(new NeverCrash.CrashHandler() { @Override public void uncaughtException(Thread t, Throwable e) { FileUtils.writeToFile(App.this, "bug " + System.currentTimeMillis(), Log.getStackTraceString(e)); } }); } @Override public void registerWith(PluginRegistry registry) { FirebaseCloudMessagingPluginRegistrant.registerWith(registry); } }dont forget to add name=".App" in the manifest file.
Do you know if this java code is really required? If you are using flutter with v2 embedding, do need this code? or is it for the older version of flutter?
@a-elhaddad thanks, your code worked well. Here's kotlin translation:
FirebaseCloudMessagingPluginRegistrant.ktimport io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugin.common.PluginRegistry
object FirebaseCloudMessagingPluginRegistrant {
fun registerWith(registry: PluginRegistry) {
if (alreadyRegisteredWith(registry)) {
return
}
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
}
private fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
val key: String = FirebaseCloudMessagingPluginRegistrant::class.java.getCanonicalName()
if (registry.hasPlugin(key)) {
return true
}
registry.registrarFor(key)
return false
}
}
Application.ktimport io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
if (registry != null) {
FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
}
}
}
I'm on the beta channel of flutter. I copied the kotlin files, set package on the top and edit the manifest to change MainActivity into Application but the application crash immediatly. It does build tho...
I ran flutter clean, tried to check my package path but. Not working, do you guys had a similar issues ?
@izio38 my solution works for master and stable branches. Did not tested on beta.
However, these proposed solutions are improvised, as it only allows the registration of 1 package, so it is not possible to use it together with WorkManager or AlarmManager, as the only package registered in the background is firebase. 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.
Wondering when this is going to be fixed. I Basically can't use the package now.
Wondering when this is going to be fixed. I Basically can't use the package now.
Like me... its impossible to get runing background notifications... I mean, the push occurs and shows the notification, but the onBackgroundMessage never works...
Most helpful comment
Wondering when this is going to be fixed. I Basically can't use the package now.