From 3450e5d5e7158bbb97f8f01dede2477ac0b6196d Mon Sep 17 00:00:00 2001 From: vanous Date: Wed, 23 Feb 2022 10:25:10 +0100 Subject: [PATCH] allow to open Android notification settings from Notification settings --- .../NotificationManagementActivity.java | 22 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + .../res/xml/notifications_preferences.xml | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/NotificationManagementActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/NotificationManagementActivity.java index a007fb5d2..a585eb0f9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/NotificationManagementActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/NotificationManagementActivity.java @@ -42,13 +42,13 @@ import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceCategory; import android.preference.PreferenceManager; +import android.provider.Settings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; @@ -108,11 +108,31 @@ public class NotificationManagementActivity extends AbstractSettingsActivity { category.removePreference(pref); } + pref = findPreference("notifications_settings"); + pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName()); + //This could open notification channel settings, if needed...: + //Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); + //intent.putExtra(Settings.EXTRA_CHANNEL_ID, GB.NOTIFICATION_CHANNEL_ID_TRANSFER); + startActivity(intent); + return true; + } + }); + if (GBApplication.isRunningTenOrLater()) { pref = findPreference("minimize_priority"); PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications"); category.removePreference(pref); } + + if (!GBApplication.isRunningOreoOrLater()) { + pref = findPreference("notifications_settings"); + PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications"); + category.removePreference(pref); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7189f706c..dcc2e659b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -142,6 +142,7 @@ Pebble Messages Support for apps that send notifications to the Pebble via PebbleKit. Generic notification support + Android notification settings …also when screen is on Do Not Disturb Block all notifications when Do Not Disturb is enabled on the phone diff --git a/app/src/main/res/xml/notifications_preferences.xml b/app/src/main/res/xml/notifications_preferences.xml index fe283c7fd..33f4ac10f 100644 --- a/app/src/main/res/xml/notifications_preferences.xml +++ b/app/src/main/res/xml/notifications_preferences.xml @@ -3,6 +3,10 @@ android:key="pref_key_notifications" android:title="@string/pref_header_notifications"> + +