From cb77df5a4d3b5d2e48f6abaeb9acb60c8cfd2149 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 25 Jul 2018 16:58:27 -0300 Subject: [PATCH] Update to SDK 27 --- android/build.gradle | 10 +++++----- .../core/notification/PushNotification.java | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 6f05c1b..be17e59 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "25" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { - minSdkVersion 16 - targetSdkVersion 23 + minSdkVersion 19 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -20,7 +20,7 @@ android { dependencies { // Google's GCM. - compile 'com.google.android.gms:play-services-gcm:10.0.1' + compile 'com.google.android.gms:play-services-gcm:15.0.1' compile 'com.facebook.react:react-native:+' diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index 9fec1de..fef71e3 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -1,10 +1,12 @@ package com.wix.reactnativenotifications.core.notification; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import com.facebook.react.bridge.ReactContext; @@ -136,13 +138,28 @@ public class PushNotification implements IPushNotification { } protected Notification.Builder getNotificationBuilder(PendingIntent intent) { - return new Notification.Builder(mContext) + + String CHANNEL_ID = "channel_01"; + String CHANNEL_NAME = "Channel Name"; + + final Notification.Builder notification = new Notification.Builder(mContext) .setContentTitle(mNotificationProps.getTitle()) .setContentText(mNotificationProps.getBody()) .setSmallIcon(mContext.getApplicationInfo().icon) .setContentIntent(intent) .setDefaults(Notification.DEFAULT_ALL) .setAutoCancel(true); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, + CHANNEL_NAME, + NotificationManager.IMPORTANCE_DEFAULT); + final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.createNotificationChannel(channel); + notification.setChannelId(CHANNEL_ID); + } + + return notification; } protected int postNotification(Notification notification, Integer notificationId) { -- 2.26.2