diff --git a/Examples/simple-fcm-client/android/app/build.gradle b/Examples/simple-fcm-client/android/app/build.gradle index 87c9dc550fbf3081d881e4e59f11906db1c5f693..f1ca431b9de224901e27d46a047123de1b174599 100644 --- a/Examples/simple-fcm-client/android/app/build.gradle +++ b/Examples/simple-fcm-client/android/app/build.gradle @@ -84,13 +84,13 @@ def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false android { - compileSdkVersion 23 + compileSdkVersion 26 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.google.firebase.quickstart.fcm" minSdkVersion 16 - targetSdkVersion 22 + targetSdkVersion 26 versionCode 1 versionName "1.0" ndk { @@ -124,12 +124,16 @@ 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 { compile project(':react-native-fcm') compile fileTree(dir: "libs", include: ["*.jar"]) - compile "com.android.support:appcompat-v7:23.0.1" + compile "com.android.support:appcompat-v7:26.1.0" compile "com.facebook.react:react-native:+" // From node_modules } diff --git a/Examples/simple-fcm-client/android/build.gradle b/Examples/simple-fcm-client/android/build.gradle index 7b16caa1fdf8917e707e1dfd1989d88b85373f7b..eced6ef3f376bfdfc71321ae9034914baf8b7de8 100644 --- a/Examples/simple-fcm-client/android/build.gradle +++ b/Examples/simple-fcm-client/android/build.gradle @@ -21,5 +21,8 @@ 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" + } } } diff --git a/Examples/simple-fcm-client/app/App.js b/Examples/simple-fcm-client/app/App.js index 895acf8de9ec51d90a388d80cf090d5e32e49baf..f383e0d1f0acc093f26e5f683e7fec760511109e 100644 --- a/Examples/simple-fcm-client/app/App.js +++ b/Examples/simple-fcm-client/app/App.js @@ -32,6 +32,12 @@ export default class App extends Component { } async componentDidMount(){ + FCM.createNotificationChannel({ + id: 'default', + name: 'Default', + description: 'used for example', + priority: 'high' + }) registerAppListener(); FCM.getInitialNotification().then(notif => { this.setState({ @@ -61,6 +67,7 @@ export default class App extends Component { FCM.presentLocalNotification({ vibrate: 500, title: 'Hello', + channel: 'default', body: 'Test Notification', big_text: 'i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large, i am large', priority: "high", diff --git a/android/build.gradle b/android/build.gradle index 8f6ed7613a8cb052f45c59a929d7e19f9c7e0f37..8a01f4b9501602dbc7db48591647fe6fac34c733 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 + compileSdkVersion 26 buildToolsVersion "25.0.2" defaultConfig { minSdkVersion 16 - targetSdkVersion 25 + targetSdkVersion 26 versionCode 1 versionName "1.0" } @@ -22,5 +22,6 @@ dependencies { compile 'com.google.firebase:firebase-core:+' compile 'com.google.firebase:firebase-messaging:+' 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 a50f0bbb1887c75588fbd40b23e55c0d7896f54d..adee2a88cf6d7c45b6a9d601004f6d76fe7c9d66 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; @@ -35,6 +38,8 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +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; @@ -75,6 +80,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 70e4e2efae2171dd33ae1bb0e8291d1d7fd957e9..f8aa8bafc6fd98c8864004661fc1c583ee6db4d2 100644 --- a/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java +++ b/android/src/main/java/com/evollu/react/fcm/SendNotificationTask.java @@ -63,7 +63,7 @@ public class SendNotificationTask extends AsyncTask { title = mContext.getPackageManager().getApplicationLabel(appInfo).toString(); } - NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext) + NotificationCompat.Builder notification = new NotificationCompat.Builder(mContext, bundle.getString("channel")) .setContentTitle(title) .setContentText(bundle.getString("body")) .setTicker(bundle.getString("ticker")) diff --git a/index.js b/index.js index dd0b3cb00d2081efbf2452b4fa9ce3e89eeeee79..0fd049eb03141df83e69e8b79911570f11df4815 100644 --- a/index.js +++ b/index.js @@ -62,6 +62,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;