changeset 487:3afdeb535e9f

notification needs a notification channel
author Carl Byington <carl@five-ten-sg.com>
date Wed, 14 Oct 2020 11:11:09 -0700
parents 6751ed7635f6
children 869070df0e80
files app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java app/src/main/res/values/colors.xml
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java	Wed Oct 14 09:07:21 2020 -0700
+++ b/app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java	Wed Oct 14 11:11:09 2020 -0700
@@ -22,6 +22,7 @@
 import com.five_ten_sg.connectbot.bean.HostBean;
 import com.five_ten_sg.connectbot.util.HostDatabase;
 import android.app.Notification;
+import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
@@ -57,6 +58,17 @@
         Resources res = context.getResources();
         Intent notificationIntent = new Intent(context, ConsoleActivity.class);
         PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
+
+        String channelID   = "com.five_ten_sg.connectbot.service";
+        String channelName = "background";
+        NotificationChannel chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE);
+        chan.setLightColor(R.color.colorAccent);
+        chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
+
+        NotificationManager manager = getNotificationManager(context);
+        assert manager != null;
+        manager.createNotificationChannel(chan);
+
         Notification notification = new Notification.Builder(context)
             .setContentTitle(res.getString(R.string.app_name))
             .setContentText(res.getString(R.string.notification_text, host.getNickname()))
@@ -64,6 +76,7 @@
             .setWhen(System.currentTimeMillis())
             .setSmallIcon(R.drawable.notification_icon)
             .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon))
+            .setChannelId(channelID)
             .setLights(rgb, 300, 1000)
             .build();
         notification.flags |= Notification.FLAG_AUTO_CANCEL;
@@ -74,6 +87,17 @@
         Resources res = context.getResources();
         Intent notificationIntent = new Intent(context, ConsoleActivity.class);
         PendingIntent contentIntent = PendingIntent.getActivity(context, ONLINE_NOTIFICATION, notificationIntent, 0);
+
+        String channelID   = "com.five_ten_sg.connectbot.service";
+        String channelName = "background";
+        NotificationChannel chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE);
+        chan.setLightColor(R.color.colorAccent);
+        chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
+
+        NotificationManager manager = getNotificationManager(context);
+        assert manager != null;
+        manager.createNotificationChannel(chan);
+
         Notification notification = new Notification.Builder(context)
             .setContentTitle(res.getString(R.string.app_name))
             .setContentText(res.getString(R.string.app_is_running))
@@ -82,6 +106,7 @@
             .setOngoing(true)
             .setSmallIcon(R.drawable.notification_icon)
             .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon))
+            .setChannelId(channelID)
             .build();
         notification.flags |= Notification.FLAG_NO_CLEAR;
         return notification;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/src/main/res/values/colors.xml	Wed Oct 14 11:11:09 2020 -0700
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="colorPrimary">#008577</color>
+    <color name="colorPrimaryDark">#00574B</color>
+    <color name="colorAccent">#D81B60</color>
+</resources>