Mercurial > 510Connectbot
comparison 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 |
comparison
equal
deleted
inserted
replaced
487:3afdeb535e9f | 488:869070df0e80 |
---|---|
38 * Based on the concept from jasta's blog post. | 38 * Based on the concept from jasta's blog post. |
39 */ | 39 */ |
40 public class ConnectionNotifier { | 40 public class ConnectionNotifier { |
41 private static final int ONLINE_NOTIFICATION = 1; | 41 private static final int ONLINE_NOTIFICATION = 1; |
42 private static final int ACTIVITY_NOTIFICATION = 2; | 42 private static final int ACTIVITY_NOTIFICATION = 2; |
43 private NotificationChannel chan = null; | |
43 | 44 |
44 protected NotificationManager getNotificationManager(Context context) { | 45 protected NotificationManager getNotificationManager(Context context) { |
45 return (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); | 46 return (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); |
46 } | 47 } |
47 | 48 |
59 Intent notificationIntent = new Intent(context, ConsoleActivity.class); | 60 Intent notificationIntent = new Intent(context, ConsoleActivity.class); |
60 PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); | 61 PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); |
61 | 62 |
62 String channelID = "com.five_ten_sg.connectbot.service"; | 63 String channelID = "com.five_ten_sg.connectbot.service"; |
63 String channelName = "background"; | 64 String channelName = "background"; |
64 NotificationChannel chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE); | 65 if (chan == null) { |
65 chan.setLightColor(R.color.colorAccent); | 66 chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE); |
66 chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); | 67 chan.setLightColor(R.color.colorAccent); |
67 | 68 chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); |
68 NotificationManager manager = getNotificationManager(context); | 69 NotificationManager manager = getNotificationManager(context); |
69 assert manager != null; | 70 assert manager != null; |
70 manager.createNotificationChannel(chan); | 71 manager.createNotificationChannel(chan); |
72 } | |
71 | 73 |
72 Notification notification = new Notification.Builder(context) | 74 Notification notification = new Notification.Builder(context) |
73 .setContentTitle(res.getString(R.string.app_name)) | 75 .setContentTitle(res.getString(R.string.app_name)) |
74 .setContentText(res.getString(R.string.notification_text, host.getNickname())) | 76 .setContentText(res.getString(R.string.notification_text, host.getNickname())) |
75 .setContentIntent(contentIntent) | 77 .setContentIntent(contentIntent) |
88 Intent notificationIntent = new Intent(context, ConsoleActivity.class); | 90 Intent notificationIntent = new Intent(context, ConsoleActivity.class); |
89 PendingIntent contentIntent = PendingIntent.getActivity(context, ONLINE_NOTIFICATION, notificationIntent, 0); | 91 PendingIntent contentIntent = PendingIntent.getActivity(context, ONLINE_NOTIFICATION, notificationIntent, 0); |
90 | 92 |
91 String channelID = "com.five_ten_sg.connectbot.service"; | 93 String channelID = "com.five_ten_sg.connectbot.service"; |
92 String channelName = "background"; | 94 String channelName = "background"; |
93 NotificationChannel chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE); | 95 if (chan == null) { |
94 chan.setLightColor(R.color.colorAccent); | 96 chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE); |
95 chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); | 97 chan.setLightColor(R.color.colorAccent); |
96 | 98 chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); |
97 NotificationManager manager = getNotificationManager(context); | 99 NotificationManager manager = getNotificationManager(context); |
98 assert manager != null; | 100 assert manager != null; |
99 manager.createNotificationChannel(chan); | 101 manager.createNotificationChannel(chan); |
102 } | |
100 | 103 |
101 Notification notification = new Notification.Builder(context) | 104 Notification notification = new Notification.Builder(context) |
102 .setContentTitle(res.getString(R.string.app_name)) | 105 .setContentTitle(res.getString(R.string.app_name)) |
103 .setContentText(res.getString(R.string.app_is_running)) | 106 .setContentText(res.getString(R.string.app_is_running)) |
104 .setContentIntent(contentIntent) | 107 .setContentIntent(contentIntent) |