Skip to content

Commit

Permalink
Merge pull request #2335 from nextcloud/pushChannel
Browse files Browse the repository at this point in the history
Add push channel for 8.x with default importance
  • Loading branch information
AndyScherzinger authored Mar 12, 2018
2 parents fcf64bc + a2606d2 commit 1c41baf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,6 @@
<string name="end_to_end_encryption_storing_keys">Storing keys</string>
<string name="copy_move_to_encrypted_folder_not_supported">Copy/move into encrypted folder currently not supported.</string>
<string name="untrusted_domain">Access through untrusted domain. Please see documentation for further info.</string>
<string name="notification_channel_push_name">Push notifications</string>
<string name="notification_channel_push_description">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.</string>
</resources>

0 comments on commit 1c41baf

Please sign in to comment.