diff --git a/packages/firebase_messaging/CHANGELOG.md b/packages/firebase_messaging/CHANGELOG.md index 0ab9e24a0793..606ae68aefbf 100644 --- a/packages/firebase_messaging/CHANGELOG.md +++ b/packages/firebase_messaging/CHANGELOG.md @@ -1,3 +1,6 @@ +## 7.0.1 +* Add Kotlin support in README.md. + ## 7.0.0 * Depend on `firebase_core` and migrate plugin to use `firebase_core` native SDK versioning features; diff --git a/packages/firebase_messaging/README.md b/packages/firebase_messaging/README.md index 14313e6b489e..15eabc96c60f 100644 --- a/packages/firebase_messaging/README.md +++ b/packages/firebase_messaging/README.md @@ -73,7 +73,8 @@ By default background messaging is not enabled. To handle messages in the backgr Note: you can find out what the latest version of the plugin is [here ("Cloud Messaging")](https://firebase.google.com/support/release-notes/android#latest_sdk_versions). -1. 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//`. +#### Java's support: +2. 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//`. ```java package io.flutter.plugins.firebasemessagingexample; @@ -98,19 +99,48 @@ By default background messaging is not enabled. To handle messages in the backgr } ``` -1. In `Application.java`, make sure to change `package io.flutter.plugins.firebasemessagingexample;` to your package's identifier. Your package's identifier should be something like `com.domain.myapplication`. +3. In `Application.java`, make sure to change `package io.flutter.plugins.firebasemessagingexample;` to your package's identifier. Your package's identifier should be something like `com.domain.myapplication`. ```java package com.domain.myapplication; ``` +#### 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 `/android/app/src/main/kotlin//`. +```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 + +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")); + } +} +``` +3. In `Application.kt`, make sure to change `package io.flutter.plugins.firebasemessagingexample` to your package's identifier. Your package's identifier should be something like `com.domain.myapplication`. + + ```kotlin + package com.domain.myapplication; + ``` +--- -1. Set name property of application in `AndroidManifest.xml`. This is typically found in `/android/app/src/main/`. +4. Set name property of application in `AndroidManifest.xml`. This is typically found in `/android/app/src/main/`. ```xml ``` -1. Define a **TOP-LEVEL** or **STATIC** function to handle background messages +5. Define a **TOP-LEVEL** or **STATIC** function to handle background messages ```dart Future myBackgroundMessageHandler(Map message) async { @@ -131,7 +161,7 @@ By default background messaging is not enabled. To handle messages in the backgr Note: the protocol of `data` and `notification` are in line with the fields defined by a [RemoteMessage](https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage). -1. Set `onBackgroundMessage` handler when calling `configure` +6. Set `onBackgroundMessage` handler when calling `configure` ```dart _firebaseMessaging.configure(