Skip to content

Commit ed24cc5

Browse files
Update README.md
1 parent a084641 commit ed24cc5

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

packages/firebase_messaging/README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ By default background messaging is not enabled. To handle messages in the backgr
7373

7474
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).
7575

76-
1. Add an `Application.java` class to your app in the same directory as your `MainActivity.java`. This is typically found in `<app-name>/android/app/src/main/java/<app-organization-path>/`.
76+
#### Java's support:
77+
2. Add an `Application.java` class to your app in the same directory as your `MainActivity.java`. This is typically found in `<app-name>/android/app/src/main/java/<app-organization-path>/`.
7778

7879
```java
7980
package io.flutter.plugins.firebasemessagingexample;
@@ -98,19 +99,48 @@ By default background messaging is not enabled. To handle messages in the backgr
9899
}
99100
```
100101

101-
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`.
102+
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`.
102103

103104
```java
104105
package com.domain.myapplication;
105106
```
107+
#### Kotlin's support:
108+
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>/`.
109+
```kotlin
110+
package io.flutter.plugins.firebasemessagingexample
111+
112+
import io.flutter.app.FlutterApplication
113+
import io.flutter.plugin.common.PluginRegistry
114+
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
115+
import io.flutter.plugins.GeneratedPluginRegistrant
116+
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
117+
118+
class Application : FlutterApplication(), PluginRegistrantCallback {
119+
120+
override fun onCreate() {
121+
super.onCreate()
122+
FlutterFirebaseMessagingService.setPluginRegistrant(this);
123+
}
124+
125+
override fun registerWith(registry: PluginRegistry?) {
126+
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
127+
}
128+
}
129+
```
130+
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`.
131+
132+
```kotlin
133+
package com.domain.myapplication;
134+
```
135+
---
106136

107-
1. Set name property of application in `AndroidManifest.xml`. This is typically found in `<app-name>/android/app/src/main/`.
137+
4. Set name property of application in `AndroidManifest.xml`. This is typically found in `<app-name>/android/app/src/main/`.
108138

109139
```xml
110140
<application android:name=".Application" ...>
111141
```
112142

113-
1. Define a **TOP-LEVEL** or **STATIC** function to handle background messages
143+
5. Define a **TOP-LEVEL** or **STATIC** function to handle background messages
114144

115145
```dart
116146
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
@@ -131,7 +161,7 @@ By default background messaging is not enabled. To handle messages in the backgr
131161
Note: the protocol of `data` and `notification` are in line with the
132162
fields defined by a [RemoteMessage](https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage).
133163

134-
1. Set `onBackgroundMessage` handler when calling `configure`
164+
6. Set `onBackgroundMessage` handler when calling `configure`
135165

136166
```dart
137167
_firebaseMessaging.configure(

0 commit comments

Comments
 (0)