diff --git a/Examples/simple-fcm-client/android/app/build.gradle b/Examples/simple-fcm-client/android/app/build.gradle index fd9274e01e9f8ee3fffc5b18f1adfb235b9b1809..8990edd98b0695b939aa11606ac90fffc7ea65b7 100644 --- a/Examples/simple-fcm-client/android/app/build.gradle +++ b/Examples/simple-fcm-client/android/app/build.gradle @@ -83,13 +83,13 @@ def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { applicationId "com.google.firebase.quickstart.fcm" minSdkVersion 16 - targetSdkVersion 22 + targetSdkVersion 27 versionCode 1 versionName "1.0" ndk { @@ -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 { diff --git a/Examples/simple-fcm-client/android/build.gradle b/Examples/simple-fcm-client/android/build.gradle index 7b16caa1fdf8917e707e1dfd1989d88b85373f7b..b0242a0eb1324dd5161d2e68773a110c727fcade 100644 --- a/Examples/simple-fcm-client/android/build.gradle +++ b/Examples/simple-fcm-client/android/build.gradle @@ -3,10 +3,14 @@ buildscript { repositories { jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' - classpath 'com.google.gms:google-services:3.0.0' + classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.google.gms:google-services:3.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -21,5 +25,9 @@ allprojects { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } + maven { + url 'https://maven.google.com/' + name 'Google' + } } } diff --git a/Examples/simple-fcm-client/android/gradle/wrapper/gradle-wrapper.properties b/Examples/simple-fcm-client/android/gradle/wrapper/gradle-wrapper.properties index a27341b30486873964e52bffb3529af62bd82a3a..02df1b0c447d542e545ccb4b86677f754372c15b 100644 --- a/Examples/simple-fcm-client/android/gradle/wrapper/gradle-wrapper.properties +++ b/Examples/simple-fcm-client/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jan 06 16:34:59 EST 2017 +#Thu May 03 13:49:29 EDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME 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 diff --git a/Examples/simple-fcm-client/app/App.js b/Examples/simple-fcm-client/app/App.js index 62f42c89c24e9e848e664f9ce9b20322cd525a5b..651427d57bf27c18b55e87ffe363727346b241f2 100644 --- a/Examples/simple-fcm-client/app/App.js +++ b/Examples/simple-fcm-client/app/App.js @@ -35,6 +35,12 @@ class MainPage extends Component { } async componentDidMount() { + FCM.createNotificationChannel({ + id: 'default', + name: 'Default', + description: 'used for example', + priority: 'high' + }) registerAppListener(this.props.navigation); FCM.getInitialNotification().then(notif => { this.setState({ @@ -75,6 +81,7 @@ class MainPage extends Component { showLocalNotification() { FCM.presentLocalNotification({ + channel: 'default', id: new Date().valueOf().toString(), // (optional for instant notification) title: "Test Notification with action", // as FCM payload body: "Force touch to reply", // as FCM payload (required) diff --git a/android/build.gradle b/android/build.gradle index 6bcebe97e5a3c311de1880f4d521992c18822a60..368f74ce3723e42f20531465188d22c7695ec714 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,9 +1,9 @@ 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_TARGET_SDK_VERSION = 25 -def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "11.+" +def DEFAULT_TARGET_SDK_VERSION = 26 +def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "12.+" android { compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION @@ -29,5 +29,6 @@ dependencies { compile "com.google.firebase:firebase-core:$googlePlayServicesVersion" compile "com.google.firebase:firebase-messaging:$googlePlayServicesVersion" compile 'me.leolin:ShortcutBadger:1.1.17@aar' + compile "com.android.support:support-core-utils:26.1.0" } diff --git a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java index d91bc35de660725b45c7d755528b36910ff6e970..e68b759cd0e260b7713668dd6e6d9618318f444a 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java @@ -1,6 +1,8 @@ package com.evollu.react.fcm; import android.app.Activity; +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; @@ -23,6 +25,7 @@ import com.google.firebase.messaging.RemoteMessage; import com.google.firebase.messaging.RemoteMessage.Notification; import android.app.Application; +import android.os.Build; import android.os.Bundle; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.content.LocalBroadcastManager; @@ -36,6 +39,8 @@ import java.util.Set; import java.util.UUID; import com.google.firebase.FirebaseApp; +import static android.content.Context.NOTIFICATION_SERVICE; + public class FIRMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ActivityEventListener { private final static String TAG = FIRMessagingModule.class.getCanonicalName(); private FIRLocalMessagingHelper mFIRLocalMessagingHelper; @@ -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 public void getFCMToken(Promise promise) { try { diff --git a/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java b/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java index dc0dc8ae1f0ea778df4d906bdf03b5dcf5c87f15..df966356fc1e244642d9e6f2b72f68ef9b6d2985 100644 --- a/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java +++ b/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java @@ -78,7 +78,7 @@ public class SendNotificationTask extends AsyncTask { String subText = bundle.getString("sub_text"); 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) .setContentText(body) .setTicker(ticker) diff --git a/index.js b/index.js index aaa740893915f538f570c76e39afbc30eb6869dd..c2781c400424d63e7f8a21da7c10e4343b549df1 100644 --- a/index.js +++ b/index.js @@ -90,6 +90,12 @@ FCM.requestPermissions = () => { return RNFIRMessaging.requestPermissions(); }; +FCM.createNotificationChannel = (channel) => { + if (Platform.OS === 'android') { + return RNFIRMessaging.createNotificationChannel(channel); + } +} + FCM.presentLocalNotification = (details) => { details.id = details.id || new Date().getTime().toString(); details.local_notification = true;