Fix startup crash before Oreo

This commit is contained in:
emanuele-f 2021-03-07 12:35:45 +01:00
parent fb1fcd77ab
commit d04b93edd0

View File

@ -263,14 +263,13 @@ public class CaptureService extends VpnService implements Runnable {
}
private void setupNotifications() {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel chan = new NotificationChannel(NOTIFY_CHAN_VPNSERVICE,
NOTIFY_CHAN_VPNSERVICE, NotificationManager.IMPORTANCE_LOW); // low: no sound
nm.createNotificationChannel(chan);
NotificationChannel chan = new NotificationChannel(NOTIFY_CHAN_VPNSERVICE,
NOTIFY_CHAN_VPNSERVICE, NotificationManager.IMPORTANCE_LOW); // low: no sound
nm.createNotificationChannel(chan);
}
// Notification builder
PendingIntent pi = PendingIntent.getActivity(this, 0,
@ -278,7 +277,6 @@ public class CaptureService extends VpnService implements Runnable {
mNotificationBuilder = new NotificationCompat.Builder(this, NOTIFY_CHAN_VPNSERVICE)
.setSmallIcon(R.drawable.ic_logo)
.setColor(getColor(R.color.colorPrimary))
.setContentIntent(pi)
.setOngoing(true)
.setAutoCancel(false)
@ -286,6 +284,9 @@ public class CaptureService extends VpnService implements Runnable {
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_LOW); // see IMPORTANCE_LOW
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
mNotificationBuilder.setColor(getColor(R.color.colorPrimary));
if(Utils.isTv(this)) {
// This is the icon which is visualized
Drawable banner = ContextCompat.getDrawable(this, R.drawable.banner);