diff --git a/android/build.gradle b/android/build.gradle index 6f05c1b10521811ced69a91c3e775fcbb308dd60..be17e59d02e7764fd2f26c006193cb77a9c299e1 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 9fec1de6bcce2f68f96b88a50ab5963a256d34af..fef71e340af64adcc3f91cd6dbb3b480dcf77533 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) {