I'm using firebase_messaging in my flutter application.
To handle background messages with firebase messaging in pub they suggested to create new Application.java file and replace java file name in AndroidManifest file.
In my application i'm using kotlin and i already implemented some native code in MainActivity.kt
So how to write this code in kotlin.
package io.flutter.plugins.firebasemessagingexample;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
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);
}
}
it is mandatory to replace MainActivity to Application in AndroidManifest file? because i'm having some native code in MainActivity file
Hi @msarkrish
this doesn't appear to be a bug w/ firebase messaging;
if you need assistance for your code
please see https://flutter.dev/community for resources,
check our guides or
you may also get some help if you post it on Stack Overflow.
Closing, as this isn't an issue with FlutterFire itself,
if you disagree please write in the comments and I will reopen it
Thank you
@msarkrish
package io.flutter.plugins.firebasemessagingexample
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
GeneratedPluginRegistrant.registerWith(registry)
}
}
Could everyone who still has this problem please file a new issue with the exact descriptions what happens, logs and the output of 'flutter doctor -v' please.
All system setups can be slightly different so it's always better to open new issues and reference related issues.
This isn't a bug but it is a documentation request for implementing this using Kotlin instead of java since Android is moving away from java development. I'm having the same issue.
I agree, the documentation could be better and I can't seem to find anything in the community or SO.
Hi all, I had the same issue in my flutter project. However, when I created an Application.kt file and pasted the code from the README, the Kotlin plugin in IntelliJ automatically prompted to covert the Java code to Kotlin for me:

The result was as follows. I simply had to add the override keywords

Hope this helps!
Most helpful comment
@msarkrish