Skip to content

Commit 05aa697

Browse files
Added implementation of notification to flutter_template.
1 parent f8580bb commit 05aa697

File tree

16 files changed

+785
-46
lines changed

16 files changed

+785
-46
lines changed

Template/MobileTemplate/flutter_template/android/app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if (flutterVersionName == null) {
2424
apply plugin: 'com.android.application'
2525
apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
apply plugin: 'com.google.gms.google-services'
2728

2829
android {
2930
compileSdkVersion 30
@@ -35,7 +36,7 @@ android {
3536
defaultConfig {
3637
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3738
applicationId "com.opentouryo.flutter_template"
38-
minSdkVersion 16
39+
minSdkVersion 23 // 16 -> 23
3940
targetSdkVersion 30
4041
versionCode flutterVersionCode.toInteger()
4142
versionName flutterVersionName
@@ -60,4 +61,5 @@ flutter {
6061

6162
dependencies {
6263
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
64+
implementation "com.google.firebase:firebase-messaging:22.0.0"
6365
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�u��������B

Template/MobileTemplate/flutter_template/android/app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.opentouryo.flutter_template">
33
<application
4+
android:name=".Application"
45
android:label="flutter_template"
56
android:icon="@mipmap/ic_launcher"
67
android:networkSecurityConfig="@xml/network_security_config">
8+
<meta-data
9+
android:name="com.google.firebase.messaging.default_notification_icon"
10+
android:resource="@drawable/notification_icon" />
11+
<meta-data
12+
android:name="com.google.firebase.messaging.default_notification_color"
13+
android:resource="@color/colorPrimary" />
714
<activity
815
android:name=".MainActivity"
916
android:launchMode="singleTop"
@@ -46,6 +53,11 @@
4653
<category android:name="android.intent.category.BROWSABLE" />
4754
<data android:scheme="http" android:host="opentouryo.com" />
4855
</intent-filter>
56+
<!-- FLUTTER NOTIFICATION -->
57+
<intent-filter>
58+
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
59+
<category android:name="android.intent.category.DEFAULT" />
60+
</intent-filter>
4961
</activity>
5062
<!-- Don't delete the meta-data below.
5163
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.opentouryo.flutter_template
2+
3+
import io.flutter.app.FlutterApplication
4+
import io.flutter.plugin.common.PluginRegistry
5+
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
6+
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService
7+
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin
8+
9+
class Application : FlutterApplication(), PluginRegistrantCallback {
10+
override fun onCreate() {
11+
super.onCreate()
12+
FlutterFirebaseMessagingBackgroundService.setPluginRegistrant(this)
13+
}
14+
15+
override fun registerWith(registry: PluginRegistry?) {
16+
val key: String? = FlutterFirebaseMessagingPlugin::class.java.canonicalName
17+
if (!registry?.hasPlugin(key)!!) {
18+
FlutterFirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin"));
19+
}
20+
}
21+
}
5.88 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#e26338</color>
4+
</resources>

Template/MobileTemplate/flutter_template/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ buildscript {
88
dependencies {
99
classpath 'com.android.tools.build:gradle:4.1.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11+
classpath 'com.google.gms:google-services:4.3.5'
1112
}
1213
}
1314

Template/MobileTemplate/flutter_template/lib/generated_plugin_registrant.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
// ignore_for_file: lines_longer_than_80_chars
66

7+
import 'package:firebase_core_web/firebase_core_web.dart';
8+
import 'package:firebase_messaging_web/firebase_messaging_web.dart';
79
import 'package:url_launcher_web/url_launcher_web.dart';
810

911
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
1012

1113
// ignore: public_member_api_docs
1214
void registerPlugins(Registrar registrar) {
15+
FirebaseCoreWeb.registerWith(registrar);
16+
FirebaseMessagingWeb.registerWith(registrar);
1317
UrlLauncherPlugin.registerWith(registrar);
1418
registrar.registerMessageHandler();
1519
}

0 commit comments

Comments
 (0)