Skip to content

Commit

Permalink
Merge pull request #2 from evollu/sdk-26
Browse files Browse the repository at this point in the history
Sdk 26
  • Loading branch information
Titozzz authored Feb 5, 2018
2 parents 7c6b143 + 2e60653 commit bc7bd73
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
10 changes: 7 additions & 3 deletions Examples/simple-fcm-client/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions Examples/simple-fcm-client/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
7 changes: 7 additions & 0 deletions Examples/simple-fcm-client/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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"
}

47 changes: 47 additions & 0 deletions android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,6 +25,7 @@
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;
Expand All @@ -35,6 +38,8 @@
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;
Expand Down Expand Up @@ -75,6 +80,48 @@ public void requestPermissions(Promise promise){
}
}

@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected Void doInBackground(Void... params) {
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"))
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bc7bd73

Please sign in to comment.