diff --git a/res/values/strings.xml b/res/values/strings.xml --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -315,7 +315,7 @@ Per-device settings can be found under \'Plugin settings\' from within a device. Show persistent notification Required by Android since Android 8.0 - Since Android 9.0, this notification can only be minimized by long tapping on it + Since Android 9.0, this notification can only be disabled by user input Extra options Privacy options diff --git a/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java b/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java --- a/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java +++ b/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java @@ -1,10 +1,13 @@ package org.kde.kdeconnect.UserInterface; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; +import android.provider.Settings; import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Helpers.DeviceHelper; @@ -80,16 +83,29 @@ notificationSwitch.setTitle(R.string.setting_persistent_notification); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { notificationSwitch.setSummary(R.string.setting_persistent_notification_pie_description); - notificationSwitch.setEnabled(false); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationSwitch.setSummary(R.string.setting_persistent_notification_oreo_description); - notificationSwitch.setEnabled(false); } notificationSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + final boolean isChecked = (Boolean)newValue; - NotificationHelper.setPersistentNotificationEnabled(context, isChecked); - BackgroundService.RunCommand(context, service -> service.changePersistentNotificationVisibility(isChecked)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Intent intent = new Intent(); + if(android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1){ + intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS"); + intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName()); + }else { + intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setData(Uri.parse("package:" + context.getPackageName())); + } + context.startActivity(intent); + } + else { + NotificationHelper.setPersistentNotificationEnabled(context, isChecked); + BackgroundService.RunCommand(context, service -> service.changePersistentNotificationVisibility(isChecked)); + } return true; }); screen.addPreference(notificationSwitch);