From 3b182160707f363a9508ac42c55379726a56922a Mon Sep 17 00:00:00 2001
From: Diego Mello <diegolmello@gmail.com>
Date: Thu, 26 Jul 2018 11:19:00 -0300
Subject: [PATCH] [FIX] Android 8 notifications (#382)

<!-- INSTRUCTION: Keep the line below to notify all core developers about this new PR -->
@RocketChat/ReactNative

<!-- INSTRUCTION: Inform the issue number that this PR closes, or remove the line below -->
Closes #380

<!-- INSTRUCTION: Tell us more about your PR with screen shots if you can -->
---
 .../reactnative/CustomPushNotification.java   | 20 +++++++++++++++++--
 package-lock.json                             |  5 ++---
 package.json                                  |  2 +-
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java b/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java
index 5ada8975b..3c06b53c4 100644
--- a/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java
+++ b/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java
@@ -1,6 +1,8 @@
 package chat.rocket.reactnative;
 
 import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.res.Resources;
@@ -8,6 +10,7 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.media.AudioManager;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.provider.Settings.System;
 import android.media.RingtoneManager;
@@ -33,8 +36,10 @@ public class CustomPushNotification extends PushNotification {
         String title = bundle.getString("title");
         String message = bundle.getString("message");
 
-        final Notification.Builder notification = new Notification.Builder(mContext);
-        notification
+        String CHANNEL_ID = "rocketchatrn_channel_01";
+        String CHANNEL_NAME = "All";
+
+        final Notification.Builder notification = new Notification.Builder(mContext)
             .setSmallIcon(smallIconResId)
             .setContentIntent(intent)
             .setContentTitle(title)
@@ -45,6 +50,17 @@ public class CustomPushNotification extends PushNotification {
             .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);
+        }
+
         Bitmap largeIconBitmap = BitmapFactory.decodeResource(res, largeIconResId);
         notification.setLargeIcon(largeIconBitmap);
 
diff --git a/package-lock.json b/package-lock.json
index 70161af48..8ae8443d7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16105,9 +16105,8 @@
       }
     },
     "react-native-notifications": {
-      "version": "1.1.19",
-      "resolved": "https://registry.npmjs.org/react-native-notifications/-/react-native-notifications-1.1.19.tgz",
-      "integrity": "sha512-s0zHNBzuskKnCVjQJ92A2x0b+ZZGEjg+Rp5Mmrx6ei0NRZpi85n8QOsINYNLyFrWcBLJKFc/pjXR8+VYUO4xyw==",
+      "version": "git+https://github.com/RocketChat/react-native-notifications.git#cb77df5a4d3b5d2e48f6abaeb9acb60c8cfd2149",
+      "from": "git+https://github.com/RocketChat/react-native-notifications.git",
       "requires": {
         "core-js": "^1.0.0",
         "uuid": "^2.0.3"
diff --git a/package.json b/package.json
index 0711208d2..98e21fb4b 100644
--- a/package.json
+++ b/package.json
@@ -54,7 +54,7 @@
     "react-native-meteor": "^1.4.0",
     "react-native-modal": "^6.4.0",
     "react-native-navigation": "^1.1.474",
-    "react-native-notifications": "^1.1.19",
+    "react-native-notifications": "git+https://github.com/RocketChat/react-native-notifications.git",
     "react-native-optimized-flatlist": "^1.0.4",
     "react-native-picker-select": "^4.0.0",
     "react-native-responsive-ui": "^1.1.1",
-- 
GitLab