Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit ebf2db2

Browse files
authored
Add firebase_messaging (#33)
1 parent 38ad48d commit ebf2db2

File tree

77 files changed

+2729
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2729
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## v0.0.2+1
2+
3+
* Added workaround for https://github.com/flutter/flutter/issues/9694 to README
4+
* Moved code to https://github.com/flutter/plugins
5+
6+
## v0.0.2
7+
8+
* Updated to latest plugin API
9+
10+
## v0.0.1+2
11+
12+
* Downgraded gradle dependency for example app to make `flutter run` happy
13+
14+
## v0.0.1+1
15+
16+
* Updated README with installation instructions
17+
* Added CHANGELOG
18+
19+
## v0.0.1
20+
21+
* Initial Release

packages/firebase_messaging/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright 2017 The Chromium Authors. All rights reserved.
2+
Redistribution and use in source and binary forms, with or without
3+
modification, are permitted provided that the following conditions are
4+
met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google Inc. nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/firebase_messaging/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Firebase Cloud Messaging for Flutter
2+
3+
[![Build Status](https://travis-ci.org/flutter/firebase_messaging.svg?branch=master)](https://travis-ci.org/flutter/firebase_messaging)
4+
[![pub package](https://img.shields.io/pub/v/firebase_messaging.svg)](https://pub.dartlang.org/packages/firebase_messaging)
5+
6+
**WARNING: This is incomplete and experimental.**
7+
8+
This plugin allows Flutter apps to interact with the [Firebase Cloud Messaging (FCM) API](https://firebase.google.com/docs/cloud-messaging/) from Dart code.
9+
10+
With this plugin, your Flutter app can receive and process push notifications as well as data messages on Android and iOS. Read Firebase's [About FCM Messages](https://firebase.google.com/docs/cloud-messaging/concept-options) to learn more about the differences between notification messages and data messages.
11+
12+
Not all features of the API are implemented in the plugin yet. If something is missing feel free to send a [pull request](https://github.com/flutter/firebase_messaging/pull/new/master) or file an [issue](https://github.com/flutter/firebase_messaging/issues/new).
13+
14+
## Getting Started
15+
16+
Check out the `example` directory for a sample app that uses this plugin. To learn more about Flutter plugins in general, view our [online documentation](https://flutter.io/platform-plugins).
17+
18+
### Add the Plugin
19+
20+
Open the `pubspec.yaml` file of your app and under `dependencies` add a line for this plugin:
21+
22+
```yaml
23+
dependencies:
24+
firebase_messaging: <version you want to depend on>
25+
```
26+
27+
You can find the most recent version of the plugin on [pub](https://pub.dartlang.org/packages/firebase_messaging).
28+
29+
### Android Integration
30+
31+
To integrate your plugin into the Android part of your app, follow these steps:
32+
33+
1. Using the [Firebase Console](https://console.firebase.google.com/) add an Android app to your project: Follow the assistant, download the generated `google-services.json` file and place it inside `android/app`. Next, modify the `android/build.gradle` file and the `android/app/build.gradle` file to add the Google services plugin as described by the Firebase assistant.
34+
35+
1. (optional, but recommended) If want to be notified in your app (via `onResume` and `onLaunch`, see below) when the user clicks on a notification in the system tray include the following `intent-filter` within the `<activity>` tag of your `android/app/src/main/AndroidManifest.xml`:
36+
```xml
37+
<intent-filter>
38+
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
39+
<category android:name="android.intent.category.DEFAULT" />
40+
</intent-filter>
41+
```
42+
43+
### iOS Integration
44+
45+
To integrate your plugin into the iOS part of your app, follow these steps:
46+
47+
1. Generate the certificates required by Apple for receiving push notifications following [this guide](https://firebase.google.com/docs/cloud-messaging/ios/certs) in the Firebase docs. You can skip the section titled "Create the Provisioning Profile".
48+
49+
1. Using the [Firebase Console](https://console.firebase.google.com/) add an iOS app to your project: Follow the assistant, download the generated `GoogleService-Info.plist` file, open `ios/Runner.xcworkspace` with Xcode, and within Xcode place the file inside `ios/Runner`. **Don't** follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.
50+
51+
1. In Xcode, select `Runner` in the Project Navigator. In the Capabilities Tab turn on `Push Notifications`.
52+
53+
1. Remove the `use_frameworks!` line from `ios/Podfile` (workaround for [flutter/flutter#9694](https://github.com/flutter/flutter/issues/9694)).
54+
55+
1. Follow the steps in the "[Upload your APNs certificate](https://firebase.google.com/docs/cloud-messaging/ios/client#upload_your_apns_certificate)" section of the Firebase docs.
56+
57+
### Dart/Flutter Integration
58+
59+
From your Dart code, you need to import the plugin and instantiate it:
60+
61+
```dart
62+
import 'package:firebase_messaging/firebase_messaging.dart';
63+
64+
final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
65+
```
66+
67+
Next, you should probably request permissions for receiving Push Notifications. For this, call `_firebaseMessaging.requestNotificationPermissions()`. This will bring up a permissions dialog for the user to confirm on iOS. It's a no-op on Android. Last, but not least, register `onMessage`, `onResume`, and `onLaunch` callbacks via `_firebaseMessaging.configure()` to listen for incoming messages (see table below for more information).
68+
69+
## Receiving Messages
70+
71+
Messages are sent to your Flutter app via the `onMessage`, `onLaunch`, and `onResume` callbacks that you configured with the plugin during setup. Here is how different message types are delivered on the supported platforms:
72+
73+
| | App in Foreground | App in Background | App Terminated |
74+
| --------------------------: | ----------------- | ----------------- | -------------- |
75+
| **Notification on Android** | `onMessage` | Notification is delivered to system tray. When the user clicks on it to open app `onResume` fires if `click_action: FLUTTER_NOTIFICATION_CLICK` is set (see below). | Notification is delivered to system tray. When the user clicks on it to open app `onLaunch` fires if `click_action: FLUTTER_NOTIFICATION_CLICK` is set (see below). |
76+
| **Notification on iOS** | `onMessage` | Notification is delivered to system tray. When the user clicks on it to open app `onResume` fires. | Notification is delivered to system tray. When the user clicks on it to open app `onLaunch` fires. |
77+
| **Data Message on Android** | `onMessage` | `onMessage` while app stays in the background. | *not supported by plugin, message is lost* |
78+
| **Data Message on iOS** | `onMessage` | Message is stored by FCM and delivered to app via `onMessage` when the app is brought back to foreground. | Message is stored by FCM and delivered to app via `onMessage` when the app is brought back to foreground. |
79+
80+
Additional reading: Firebase's [About FCM Messages](https://firebase.google.com/docs/cloud-messaging/concept-options).
81+
82+
## Sending Messages
83+
Refer to the [Firebase documentation](https://firebase.google.com/docs/cloud-messaging/) about FCM for all the details about sending messages to your app. When sending a notification message to an Android device, you need to make sure to set the `click_action` property of the message to `FLUTTER_NOTIFICATION_CLICK`. Otherwise the plugin will be unable to deliver the notification to your app when the users clicks on it in the system tray.
84+
85+
For testing purposes, the simplest way to send a notification is via the [Firebase Console](https://firebase.google.com/docs/cloud-messaging/send-with-console). Make sure to include `click_action: FLUTTER_NOTIFICATION_CLICK` as a "Custom data" key-value-pair (under "Advanced options") when targeting an Android device. The Firebase Console does not support sending data messages.
86+
87+
Alternatively, a notification or data message can be sent from a terminal:
88+
89+
```shell
90+
DATA='{"notification": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "body": "this is a body","title": "this is a title"}, "priority": "high", "data": {"id": "1", "status": "done"}, "to": "<FCM TOKEN>"}'
91+
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=<FCM SERVER KEY>"
92+
```
93+
94+
Remove the `notification` property in `DATA` to send a data message.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
/.idea/libraries
5+
.DS_Store
6+
/build
7+
/captures
8+
9+
/gradle
10+
/gradlew
11+
/gradlew.bat
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android" name="Android">
5+
<configuration />
6+
</facet>
7+
</component>
8+
<component name="NewModuleRootManager" inherit-compiler-output="true">
9+
<exclude-output />
10+
<content url="file://$MODULE_DIR$">
11+
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
12+
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
13+
<sourceFolder url="file://$MODULE_DIR$/src/main/gen" isTestSource="false" />
14+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
15+
</content>
16+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
<orderEntry type="library" name="Flutter for Android" level="project" />
19+
</component>
20+
</module>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
group 'io.flutter.plugins.firebase_messaging'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:2.3.0'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
jcenter()
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
22+
android {
23+
compileSdkVersion 25
24+
buildToolsVersion '25.0.0'
25+
26+
defaultConfig {
27+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
28+
}
29+
lintOptions {
30+
disable 'InvalidPackage'
31+
}
32+
dependencies {
33+
compile 'com.google.firebase:firebase-core:10.2.1'
34+
compile 'com.google.firebase:firebase-messaging:10.2.4'
35+
}
36+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id=":firebase_messaging" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../example/android" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":firebase_messaging" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
13+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
14+
<afterSyncTasks>
15+
<task>generateDebugSources</task>
16+
</afterSyncTasks>
17+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
18+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
19+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
20+
<option name="RES_FOLDERS_RELATIVE_PATH" value="" />
21+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
22+
<option name="PROJECT_TYPE" value="1" />
23+
</configuration>
24+
</facet>
25+
</component>
26+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
27+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
28+
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
29+
<exclude-output />
30+
<content url="file://$MODULE_DIR$">
31+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
41+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
42+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
43+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
44+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
45+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
62+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
63+
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
64+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
65+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
66+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
67+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
68+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
69+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
70+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
71+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
78+
</content>
79+
<content url="file://$MODULE_DIR$/../example/build/firebase_messaging">
80+
<sourceFolder url="file://$MODULE_DIR$/../example/build/firebase_messaging/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/../example/build/firebase_messaging/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
82+
<excludeFolder url="file://$MODULE_DIR$/../example/build/firebase_messaging/tmp" />
83+
</content>
84+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
85+
<orderEntry type="sourceFolder" forTests="false" />
86+
<orderEntry type="library" exported="" name="flutter" level="project" />
87+
<orderEntry type="library" exported="" name="firebase-analytics-10.2.1" level="project" />
88+
<orderEntry type="library" exported="" name="firebase-messaging-10.2.4" level="project" />
89+
<orderEntry type="library" exported="" name="firebase-iid-10.2.4" level="project" />
90+
<orderEntry type="library" exported="" name="firebase-core-10.2.1" level="project" />
91+
<orderEntry type="library" exported="" name="firebase-common-10.2.4" level="project" />
92+
<orderEntry type="library" exported="" name="firebase-analytics-impl-10.2.1" level="project" />
93+
<orderEntry type="library" exported="" name="play-services-tasks-10.2.4" level="project" />
94+
<orderEntry type="library" exported="" name="support-annotations-24.0.0" level="project" />
95+
<orderEntry type="library" exported="" name="play-services-basement-10.2.4" level="project" />
96+
<orderEntry type="library" exported="" name="support-v4-24.0.0" level="project" />
97+
<orderEntry type="library" exported="" name="android-android-25" level="project" />
98+
</component>
99+
</module>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'firebase_messaging'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.firebase_messaging"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
8+
<application>
9+
<service android:name=".FlutterFirebaseInstanceIDService">
10+
<intent-filter>
11+
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
12+
</intent-filter>
13+
</service>
14+
<service android:name=".FlutterFirebaseMessagingService">
15+
<intent-filter>
16+
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
17+
</intent-filter>
18+
</service>
19+
</application>
20+
</manifest>

0 commit comments

Comments
 (0)