Skip to content

[📚] [firebase_messaging] Add "Application.kt" for Kotlin support. #3454

Closed
@beshr-eldebuch

Description

@beshr-eldebuch

For new projects with Kotlin support, the project only contains MainActivity.kt and not Java, and as for now, docs doesn't support it.
image

I suggest adding the following to GettingStarted.

Kotlin's support.
2. Add an Application.kt class to your app in the same directory as your MainActivity.kt. This is typically found in <app-name>/android/app/src/main/kotlin/<app-organization-path>/ .

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?) {
        io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    }
}
  1. In Application.kt, make sure to change the package io.flutter.plugins.firebasemessagingexample to your package's identifier. Your package's identifier should be something like com.domain.myapplication.
    package com.domain.myapplication;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions