From d04b93edd01c83e02229973a7c2e3e1ddcd13ae3 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Sun, 7 Mar 2021 12:35:45 +0100 Subject: [PATCH] Fix startup crash before Oreo --- .../remote_capture/CaptureService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java b/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java index 9d53acbc..a2e961d0 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java +++ b/app/src/main/java/com/emanuelef/remote_capture/CaptureService.java @@ -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);