Commit cb2c6ccf authored by Libin Lu's avatar Libin Lu Committed by GitHub

Merge pull request #699 from evollu/sdk-26

add channel
parents 6dbffd50 e7f0ad93
...@@ -83,13 +83,13 @@ def enableSeparateBuildPerCPUArchitecture = false ...@@ -83,13 +83,13 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false def enableProguardInReleaseBuilds = false
android { android {
compileSdkVersion 23 compileSdkVersion 27
buildToolsVersion "23.0.1" buildToolsVersion "27.0.3"
defaultConfig { defaultConfig {
applicationId "com.google.firebase.quickstart.fcm" applicationId "com.google.firebase.quickstart.fcm"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 22 targetSdkVersion 27
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
ndk { ndk {
...@@ -123,6 +123,10 @@ android { ...@@ -123,6 +123,10 @@ android {
} }
} }
} }
configurations.all {
resolutionStrategy.force 'com.android.support:support-core-utils:26.1.0'
resolutionStrategy.force 'com.android.support:support-core-ui:26.1.0'
}
} }
dependencies { dependencies {
......
...@@ -3,10 +3,14 @@ ...@@ -3,10 +3,14 @@
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.google.gms:google-services:3.0.0' classpath 'com.google.gms:google-services:3.1.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
...@@ -21,5 +25,9 @@ allprojects { ...@@ -21,5 +25,9 @@ allprojects {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android" url "$rootDir/../node_modules/react-native/android"
} }
maven {
url 'https://maven.google.com/'
name 'Google'
}
} }
} }
#Fri Jan 06 16:34:59 EST 2017 #Thu May 03 13:49:29 EDT 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
...@@ -35,6 +35,12 @@ class MainPage extends Component { ...@@ -35,6 +35,12 @@ class MainPage extends Component {
} }
async componentDidMount() { async componentDidMount() {
FCM.createNotificationChannel({
id: 'default',
name: 'Default',
description: 'used for example',
priority: 'high'
})
registerAppListener(this.props.navigation); registerAppListener(this.props.navigation);
FCM.getInitialNotification().then(notif => { FCM.getInitialNotification().then(notif => {
this.setState({ this.setState({
...@@ -75,6 +81,7 @@ class MainPage extends Component { ...@@ -75,6 +81,7 @@ class MainPage extends Component {
showLocalNotification() { showLocalNotification() {
FCM.presentLocalNotification({ FCM.presentLocalNotification({
channel: 'default',
id: new Date().valueOf().toString(), // (optional for instant notification) id: new Date().valueOf().toString(), // (optional for instant notification)
title: "Test Notification with action", // as FCM payload title: "Test Notification with action", // as FCM payload
body: "Force touch to reply", // as FCM payload (required) body: "Force touch to reply", // as FCM payload (required)
......
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
def DEFAULT_COMPILE_SDK_VERSION = 25 def DEFAULT_COMPILE_SDK_VERSION = 26
def DEFAULT_BUILD_TOOLS_VERSION = "25.0.2" def DEFAULT_BUILD_TOOLS_VERSION = "25.0.2"
def DEFAULT_TARGET_SDK_VERSION = 25 def DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "11.+" def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "12.+"
android { android {
compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
...@@ -29,5 +29,6 @@ dependencies { ...@@ -29,5 +29,6 @@ dependencies {
compile "com.google.firebase:firebase-core:$googlePlayServicesVersion" compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
compile "com.google.firebase:firebase-messaging:$googlePlayServicesVersion" compile "com.google.firebase:firebase-messaging:$googlePlayServicesVersion"
compile 'me.leolin:ShortcutBadger:1.1.17@aar' compile 'me.leolin:ShortcutBadger:1.1.17@aar'
compile "com.android.support:support-core-utils:26.1.0"
} }
package com.evollu.react.fcm; package com.evollu.react.fcm;
import android.app.Activity; import android.app.Activity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
...@@ -23,6 +25,7 @@ import com.google.firebase.messaging.RemoteMessage; ...@@ -23,6 +25,7 @@ import com.google.firebase.messaging.RemoteMessage;
import com.google.firebase.messaging.RemoteMessage.Notification; import com.google.firebase.messaging.RemoteMessage.Notification;
import android.app.Application; import android.app.Application;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
...@@ -36,6 +39,8 @@ import java.util.Set; ...@@ -36,6 +39,8 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseApp;
import static android.content.Context.NOTIFICATION_SERVICE;
public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ActivityEventListener { public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ActivityEventListener {
private final static String TAG = FIRMessagingModule.class.getCanonicalName(); private final static String TAG = FIRMessagingModule.class.getCanonicalName();
private FIRLocalMessagingHelper mFIRLocalMessagingHelper; private FIRLocalMessagingHelper mFIRLocalMessagingHelper;
...@@ -76,6 +81,48 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -76,6 +81,48 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
} }
} }
@ReactMethod
public void createNotificationChannel(ReadableMap details, Promise promise){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager mngr = (NotificationManager) getReactApplicationContext().getSystemService(NOTIFICATION_SERVICE);
String id = details.getString("id");
String name = details.getString("name");
String priority = details.getString("priority");
int importance;
switch(priority) {
case "min":
importance = NotificationManager.IMPORTANCE_MIN;
break;
case "low":
importance = NotificationManager.IMPORTANCE_LOW;
break;
case "high":
importance = NotificationManager.IMPORTANCE_HIGH;
break;
case "max":
importance = NotificationManager.IMPORTANCE_MAX;
break;
default:
importance = NotificationManager.IMPORTANCE_DEFAULT;
}
if (mngr.getNotificationChannel(id) != null) {
promise.resolve(null);
return;
}
//
NotificationChannel channel = new NotificationChannel(
id,
name,
importance);
// Configure the notification channel.
if(details.hasKey("description")){
channel.setDescription(details.getString("description"));
}
mngr.createNotificationChannel(channel);
}
promise.resolve(null);
}
@ReactMethod @ReactMethod
public void getFCMToken(Promise promise) { public void getFCMToken(Promise promise) {
try { try {
......
...@@ -78,7 +78,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> { ...@@ -78,7 +78,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
String subText = bundle.getString("sub_text"); String subText = bundle.getString("sub_text");
if (subText != null) subText = URLDecoder.decode( subText, "UTF-8" ); if (subText != null) subText = URLDecoder.decode( subText, "UTF-8" );
NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext) NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext, bundle.getString("channel"))
.setContentTitle(title) .setContentTitle(title)
.setContentText(body) .setContentText(body)
.setTicker(ticker) .setTicker(ticker)
......
...@@ -90,6 +90,12 @@ FCM.requestPermissions = () => { ...@@ -90,6 +90,12 @@ FCM.requestPermissions = () => {
return RNFIRMessaging.requestPermissions(); return RNFIRMessaging.requestPermissions();
}; };
FCM.createNotificationChannel = (channel) => {
if (Platform.OS === 'android') {
return RNFIRMessaging.createNotificationChannel(channel);
}
}
FCM.presentLocalNotification = (details) => { FCM.presentLocalNotification = (details) => {
details.id = details.id || new Date().getTime().toString(); details.id = details.id || new Date().getTime().toString();
details.local_notification = true; details.local_notification = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment