diff app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java @ 488:869070df0e80 stable-1.9.4-1

new notification channel needs android 8
author Carl Byington <carl@five-ten-sg.com>
date Wed, 14 Oct 2020 11:27:14 -0700
parents 3afdeb535e9f
children 7545103ec815
line wrap: on
line diff
--- a/app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java	Wed Oct 14 11:11:09 2020 -0700
+++ b/app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java	Wed Oct 14 11:27:14 2020 -0700
@@ -40,6 +40,7 @@
 public class ConnectionNotifier {
     private static final int ONLINE_NOTIFICATION = 1;
     private static final int ACTIVITY_NOTIFICATION = 2;
+    private NotificationChannel chan = null;
 
     protected NotificationManager getNotificationManager(Context context) {
         return (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -61,13 +62,14 @@
 
         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);
+        if (chan == null) {
+            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))
@@ -90,13 +92,14 @@
 
         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);
+        if (chan == null) {
+            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))