Skip to content

Firebase messaging-handle background message in kotlin with MainActivity file #1906

Closed
@msarkrish

Description

@msarkrish

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions