Mercurial > 510Connectbot
comparison app/src/main/java/com/five_ten_sg/connectbot/service/ConnectionNotifier.java @ 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 | 105815cce146 |
children | 869070df0e80 |
comparison
equal
deleted
inserted
replaced
486:6751ed7635f6 | 487:3afdeb535e9f |
---|---|
20 import com.five_ten_sg.connectbot.ConsoleActivity; | 20 import com.five_ten_sg.connectbot.ConsoleActivity; |
21 import com.five_ten_sg.connectbot.R; | 21 import com.five_ten_sg.connectbot.R; |
22 import com.five_ten_sg.connectbot.bean.HostBean; | 22 import com.five_ten_sg.connectbot.bean.HostBean; |
23 import com.five_ten_sg.connectbot.util.HostDatabase; | 23 import com.five_ten_sg.connectbot.util.HostDatabase; |
24 import android.app.Notification; | 24 import android.app.Notification; |
25 import android.app.NotificationChannel; | |
25 import android.app.NotificationManager; | 26 import android.app.NotificationManager; |
26 import android.app.PendingIntent; | 27 import android.app.PendingIntent; |
27 import android.app.Service; | 28 import android.app.Service; |
28 import android.content.Context; | 29 import android.content.Context; |
29 import android.content.Intent; | 30 import android.content.Intent; |
55 else | 56 else |
56 rgb = Color.WHITE; | 57 rgb = Color.WHITE; |
57 Resources res = context.getResources(); | 58 Resources res = context.getResources(); |
58 Intent notificationIntent = new Intent(context, ConsoleActivity.class); | 59 Intent notificationIntent = new Intent(context, ConsoleActivity.class); |
59 PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); | 60 PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); |
61 | |
62 String channelID = "com.five_ten_sg.connectbot.service"; | |
63 String channelName = "background"; | |
64 NotificationChannel chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE); | |
65 chan.setLightColor(R.color.colorAccent); | |
66 chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); | |
67 | |
68 NotificationManager manager = getNotificationManager(context); | |
69 assert manager != null; | |
70 manager.createNotificationChannel(chan); | |
71 | |
60 Notification notification = new Notification.Builder(context) | 72 Notification notification = new Notification.Builder(context) |
61 .setContentTitle(res.getString(R.string.app_name)) | 73 .setContentTitle(res.getString(R.string.app_name)) |
62 .setContentText(res.getString(R.string.notification_text, host.getNickname())) | 74 .setContentText(res.getString(R.string.notification_text, host.getNickname())) |
63 .setContentIntent(contentIntent) | 75 .setContentIntent(contentIntent) |
64 .setWhen(System.currentTimeMillis()) | 76 .setWhen(System.currentTimeMillis()) |
65 .setSmallIcon(R.drawable.notification_icon) | 77 .setSmallIcon(R.drawable.notification_icon) |
66 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon)) | 78 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon)) |
79 .setChannelId(channelID) | |
67 .setLights(rgb, 300, 1000) | 80 .setLights(rgb, 300, 1000) |
68 .build(); | 81 .build(); |
69 notification.flags |= Notification.FLAG_AUTO_CANCEL; | 82 notification.flags |= Notification.FLAG_AUTO_CANCEL; |
70 return notification; | 83 return notification; |
71 } | 84 } |
72 | 85 |
73 protected Notification newRunningNotification(Context context) { | 86 protected Notification newRunningNotification(Context context) { |
74 Resources res = context.getResources(); | 87 Resources res = context.getResources(); |
75 Intent notificationIntent = new Intent(context, ConsoleActivity.class); | 88 Intent notificationIntent = new Intent(context, ConsoleActivity.class); |
76 PendingIntent contentIntent = PendingIntent.getActivity(context, ONLINE_NOTIFICATION, notificationIntent, 0); | 89 PendingIntent contentIntent = PendingIntent.getActivity(context, ONLINE_NOTIFICATION, notificationIntent, 0); |
90 | |
91 String channelID = "com.five_ten_sg.connectbot.service"; | |
92 String channelName = "background"; | |
93 NotificationChannel chan = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_NONE); | |
94 chan.setLightColor(R.color.colorAccent); | |
95 chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); | |
96 | |
97 NotificationManager manager = getNotificationManager(context); | |
98 assert manager != null; | |
99 manager.createNotificationChannel(chan); | |
100 | |
77 Notification notification = new Notification.Builder(context) | 101 Notification notification = new Notification.Builder(context) |
78 .setContentTitle(res.getString(R.string.app_name)) | 102 .setContentTitle(res.getString(R.string.app_name)) |
79 .setContentText(res.getString(R.string.app_is_running)) | 103 .setContentText(res.getString(R.string.app_is_running)) |
80 .setContentIntent(contentIntent) | 104 .setContentIntent(contentIntent) |
81 .setWhen(0) | 105 .setWhen(0) |
82 .setOngoing(true) | 106 .setOngoing(true) |
83 .setSmallIcon(R.drawable.notification_icon) | 107 .setSmallIcon(R.drawable.notification_icon) |
84 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon)) | 108 .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.notification_icon)) |
109 .setChannelId(channelID) | |
85 .build(); | 110 .build(); |
86 notification.flags |= Notification.FLAG_NO_CLEAR; | 111 notification.flags |= Notification.FLAG_NO_CLEAR; |
87 return notification; | 112 return notification; |
88 | 113 |
89 } | 114 } |