Commit 4b1cd17b authored by Libin Lu's avatar Libin Lu

add channel

parent 49c1b270
......@@ -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
}
......
......@@ -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"
}
}
}
......@@ -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",
......
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"
}
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,47 @@ 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);
}
//
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 {
......
......@@ -62,7 +62,7 @@ public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
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"))
......
......@@ -62,6 +62,12 @@ FCM.requestPermissions = () => {
return RNFIRMessaging.requestPermissions();
};
FCM.createNotificationChannel = (channel) => {
if (Platform.OS === 'android') {
return RNFIRMessaging.createNotificationChannel();
}
}
FCM.presentLocalNotification = (details) => {
details.id = details.id || new Date().getTime().toString();
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