From a2606d2aab8e47da0618eba2173ffdbb78e52913 Mon Sep 17 00:00:00 2001 From: tobiaskaminsky Date: Mon, 12 Mar 2018 14:37:05 +0100 Subject: [PATCH] add push channel for 8.x with default value Signed-off-by: tobiaskaminsky --- .../firebase/NCFirebaseMessagingService.java | 8 ++++++-- src/main/java/com/owncloud/android/MainApp.java | 14 ++++++++++++-- .../ui/notifications/NotificationUtils.java | 1 + src/main/res/values/strings.xml | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java b/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java index 970fe7c736d1..01fc02464fa1 100644 --- a/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java +++ b/src/gplay/java/com/owncloud/android/services/firebase/NCFirebaseMessagingService.java @@ -32,6 +32,7 @@ import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.ui.activity.NotificationsActivity; +import com.owncloud.android.ui.notifications.NotificationUtils; import com.owncloud.android.utils.ThemeUtils; public class NCFirebaseMessagingService extends FirebaseMessagingService { @@ -57,8 +58,11 @@ private void sendNotification(String contentTitle) { .setAutoCancel(true) .setContentIntent(pendingIntent); - NotificationManager notificationManager = - (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + if ((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)) { + notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_PUSH); + } + + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); } diff --git a/src/main/java/com/owncloud/android/MainApp.java b/src/main/java/com/owncloud/android/MainApp.java index 47d0444899a6..f222b4573e95 100644 --- a/src/main/java/com/owncloud/android/MainApp.java +++ b/src/main/java/com/owncloud/android/MainApp.java @@ -330,6 +330,10 @@ public static void notificationChannels() { createChannel(notificationManager, NotificationUtils.NOTIFICATION_CHANNEL_FILE_OBSERVER, R.string.notification_channel_file_observer_name, R.string .notification_channel_file_observer_description, context); + + createChannel(notificationManager, NotificationUtils.NOTIFICATION_CHANNEL_PUSH, + R.string.notification_channel_push_name, R.string + .notification_channel_push_description, context, NotificationManager.IMPORTANCE_DEFAULT); } else { Log_OC.e(TAG, "Notification manager is null"); } @@ -339,13 +343,19 @@ public static void notificationChannels() { private static void createChannel(NotificationManager notificationManager, String channelId, int channelName, int channelDescription, Context context) { + createChannel(notificationManager, channelId, channelName, channelDescription, context, + NotificationManager.IMPORTANCE_LOW); + } + + private static void createChannel(NotificationManager notificationManager, + String channelId, int channelName, + int channelDescription, Context context, int importance) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O && getAppContext() != null && notificationManager.getNotificationChannel(channelId) == null) { CharSequence name = context.getString(channelName); String description = context.getString(channelDescription); - NotificationChannel channel = new NotificationChannel(channelId, name, - NotificationManager.IMPORTANCE_LOW); + NotificationChannel channel = new NotificationChannel(channelId, name, importance); channel.setDescription(description); channel.enableLights(false); diff --git a/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java b/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java index 551d9a0bb338..92a54e322b85 100644 --- a/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java +++ b/src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java @@ -39,6 +39,7 @@ public class NotificationUtils { public static final String NOTIFICATION_CHANNEL_MEDIA = "NOTIFICATION_CHANNEL_MEDIA"; public static final String NOTIFICATION_CHANNEL_FILE_SYNC = "NOTIFICATION_CHANNEL_FILE_SYNC"; public static final String NOTIFICATION_CHANNEL_FILE_OBSERVER = "NOTIFICATION_CHANNEL_FILE_OBSERVER"; + public static final String NOTIFICATION_CHANNEL_PUSH = "NOTIFICATION_CHANNEL_PUSH"; /** * Factory method for {@link android.support.v4.app.NotificationCompat.Builder} instances. diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 45bd585e12ce..3b452da7f589 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -770,4 +770,6 @@ Storing keys Copy/move into encrypted folder currently not supported. Access through untrusted domain. Please see documentation for further info. + Push notifications + Show push notifications sent by server, e.g. when mentioned in comments, you receive a new remote share or an announcement was posted by an admin.