[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 -->
This commit is contained in:
Diego Mello 2018-07-26 11:19:00 -03:00 committed by Guilherme Gazzo
parent 9d66a68bfd
commit 3b18216070
3 changed files with 21 additions and 6 deletions

View File

@ -1,6 +1,8 @@
package chat.rocket.reactnative; package chat.rocket.reactnative;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
@ -8,6 +10,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings.System; import android.provider.Settings.System;
import android.media.RingtoneManager; import android.media.RingtoneManager;
@ -33,8 +36,10 @@ public class CustomPushNotification extends PushNotification {
String title = bundle.getString("title"); String title = bundle.getString("title");
String message = bundle.getString("message"); String message = bundle.getString("message");
final Notification.Builder notification = new Notification.Builder(mContext); String CHANNEL_ID = "rocketchatrn_channel_01";
notification String CHANNEL_NAME = "All";
final Notification.Builder notification = new Notification.Builder(mContext)
.setSmallIcon(smallIconResId) .setSmallIcon(smallIconResId)
.setContentIntent(intent) .setContentIntent(intent)
.setContentTitle(title) .setContentTitle(title)
@ -45,6 +50,17 @@ public class CustomPushNotification extends PushNotification {
.setDefaults(Notification.DEFAULT_ALL) .setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true); .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); Bitmap largeIconBitmap = BitmapFactory.decodeResource(res, largeIconResId);
notification.setLargeIcon(largeIconBitmap); notification.setLargeIcon(largeIconBitmap);

5
package-lock.json generated
View File

@ -16105,9 +16105,8 @@
} }
}, },
"react-native-notifications": { "react-native-notifications": {
"version": "1.1.19", "version": "git+https://github.com/RocketChat/react-native-notifications.git#cb77df5a4d3b5d2e48f6abaeb9acb60c8cfd2149",
"resolved": "https://registry.npmjs.org/react-native-notifications/-/react-native-notifications-1.1.19.tgz", "from": "git+https://github.com/RocketChat/react-native-notifications.git",
"integrity": "sha512-s0zHNBzuskKnCVjQJ92A2x0b+ZZGEjg+Rp5Mmrx6ei0NRZpi85n8QOsINYNLyFrWcBLJKFc/pjXR8+VYUO4xyw==",
"requires": { "requires": {
"core-js": "^1.0.0", "core-js": "^1.0.0",
"uuid": "^2.0.3" "uuid": "^2.0.3"

View File

@ -54,7 +54,7 @@
"react-native-meteor": "^1.4.0", "react-native-meteor": "^1.4.0",
"react-native-modal": "^6.4.0", "react-native-modal": "^6.4.0",
"react-native-navigation": "^1.1.474", "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-optimized-flatlist": "^1.0.4",
"react-native-picker-select": "^4.0.0", "react-native-picker-select": "^4.0.0",
"react-native-responsive-ui": "^1.1.1", "react-native-responsive-ui": "^1.1.1",