From 23e76dd8cfdd419ab2fce80203c097f808f109bb Mon Sep 17 00:00:00 2001 From: Tad Date: Thu, 5 Apr 2018 21:46:24 -0400 Subject: [PATCH] Really fix notifications on Oreo --- app/build.gradle | 4 ++-- .../us/spotco/malwarescanner/MalwareScanner.java | 10 ++++++++++ .../spotco/malwarescanner/MalwareScannerService.java | 12 ++++++------ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 684ef73..99a1f3c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "us.spotco.malwarescanner" minSdkVersion 16 targetSdkVersion 26 - versionCode 30 - versionName "2.5" + versionCode 31 + versionName "2.6" } buildTypes { debug { diff --git a/app/src/main/java/us/spotco/malwarescanner/MalwareScanner.java b/app/src/main/java/us/spotco/malwarescanner/MalwareScanner.java index d679750..5043f23 100644 --- a/app/src/main/java/us/spotco/malwarescanner/MalwareScanner.java +++ b/app/src/main/java/us/spotco/malwarescanner/MalwareScanner.java @@ -2,8 +2,10 @@ package us.spotco.malwarescanner; import android.app.Activity; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; +import android.graphics.Color; import android.os.AsyncTask; import android.os.Build; import android.os.Environment; @@ -40,6 +42,11 @@ class MalwareScanner extends AsyncTask, Object, String> { logOutput = activity.findViewById(R.id.txtLogOutput); } else { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel detectionChannel = new NotificationChannel("DETECTION", context.getString(R.string.lblNotificationMalwareDetectionTitle), NotificationManager.IMPORTANCE_HIGH); + detectionChannel.setDescription(context.getString(R.string.lblNotificationMalwareDetectionDescription)); + notificationManager.createNotificationChannel(detectionChannel); + } } } @@ -58,6 +65,9 @@ class MalwareScanner extends AsyncTask, Object, String> { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setVisibility(Notification.VISIBILITY_SECRET); } + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + mBuilder.setChannelId("DETECTION"); + } notificationManager.notify(new Random().nextInt(), mBuilder.build()); //Log.d("Theia", result); } diff --git a/app/src/main/java/us/spotco/malwarescanner/MalwareScannerService.java b/app/src/main/java/us/spotco/malwarescanner/MalwareScannerService.java index c941722..6cb924d 100644 --- a/app/src/main/java/us/spotco/malwarescanner/MalwareScannerService.java +++ b/app/src/main/java/us/spotco/malwarescanner/MalwareScannerService.java @@ -52,6 +52,12 @@ public class MalwareScannerService extends Service { } notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel foregroundChannel = new NotificationChannel("FOREGROUND", getString(R.string.lblNotificationRealtimeTitle), NotificationManager.IMPORTANCE_LOW); + foregroundChannel.setDescription(getString(R.string.lblNotificationRealtimeDescription)); + foregroundChannel.setShowBadge(false); + notificationManager.createNotificationChannel(foregroundChannel); + } setForeground(); return START_STICKY; } @@ -96,13 +102,7 @@ public class MalwareScannerService extends Service { .setShowWhen(false); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - NotificationChannel foregroundChannel = new NotificationChannel("FOREGROUND", getString(R.string.lblNotificationRealtimeTitle), NotificationManager.IMPORTANCE_LOW); - foregroundChannel.setShowBadge(false); - foregroundChannel.setDescription(getString(R.string.lblNotificationRealtimeDescription)); - notificationManager.createNotificationChannel(foregroundChannel); foregroundNotification.setChannelId("FOREGROUND"); - //Importance seems to be getting ignored - //Users will have to manually set it to 'Low' in order to hide it from the lock screen and status bar } startForeground(-1, foregroundNotification.build()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b0724bf..48fd97e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -7,6 +7,8 @@ Scan App APKs Scan Internal Storage Scan External Storage + Malware Detection + Used to alert when malware is detected Realtime Scanner Used to show files scanned counter and maintain the background service Malware will be detected in realtime