diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-03-06 21:40:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-06 21:40:34 +0100 |
commit | 0b3e6640570ab6b19b00a63c0880801b43c00792 (patch) | |
tree | 793c3bb5897034a5ae453454e7436b2d8b386786 /app | |
parent | d8d94878a201cd1a33bb34f9c42ab68c49b82069 (diff) | |
download | AntennaPod-0b3e6640570ab6b19b00a63c0880801b43c00792.zip |
Prompt for battery optimization (#6362)
Diffstat (limited to 'app')
3 files changed, 29 insertions, 0 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9cce60469..dfe8cd77b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,7 @@ <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> + <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/> <supports-screens android:anyDensity="true" diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/NetworkPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/NetworkPreferencesFragment.java index 50de1e3c4..c1cb8adb1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/NetworkPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/NetworkPreferencesFragment.java @@ -1,9 +1,14 @@ package de.danoeh.antennapod.fragment.preferences; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.os.PowerManager; +import android.provider.Settings; import android.text.format.DateFormat; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; @@ -17,10 +22,13 @@ import java.util.Calendar; import java.util.GregorianCalendar; import java.util.concurrent.TimeUnit; +import static android.content.Context.POWER_SERVICE; + public class NetworkPreferencesFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { private static final String PREF_SCREEN_AUTODL = "prefAutoDownloadSettings"; + private static final String PREF_BATTERY_OPTIMIZATION = "prefBatteryOptimization"; private static final String PREF_PROXY = "prefProxy"; @Override @@ -59,6 +67,20 @@ public class NetworkPreferencesFragment extends PreferenceFragmentCompat new FeedRefreshIntervalDialog(getContext()).show(); return true; }); + if (Build.VERSION.SDK_INT >= 31) { + PowerManager powerManager = (PowerManager) getContext().getSystemService(POWER_SERVICE); + if (!powerManager.isIgnoringBatteryOptimizations(getContext().getPackageName())) { + findPreference(PREF_BATTERY_OPTIMIZATION).setVisible(true); + findPreference(PREF_BATTERY_OPTIMIZATION).setOnPreferenceClickListener(preference -> { + findPreference(PREF_BATTERY_OPTIMIZATION).setVisible(false); + Intent i = new Intent(); + i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + i.setData(Uri.parse("package:" + getContext().getPackageName())); + startActivity(i); + return true; + }); + } + } findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS) .setOnPreferenceChangeListener( diff --git a/app/src/main/res/xml/preferences_network.xml b/app/src/main/res/xml/preferences_network.xml index 428c891ad..34832378f 100644 --- a/app/src/main/res/xml/preferences_network.xml +++ b/app/src/main/res/xml/preferences_network.xml @@ -2,9 +2,15 @@ <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:numberpicker="http://schemas.android.com/apk/de.danoeh.antennapod" + xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:search="http://schemas.android.com/apk/com.bytehamster.lib.preferencesearch"> <PreferenceCategory android:title="@string/automation"> <Preference + android:key="prefBatteryOptimization" + android:title="@string/battery_optimization_pref_title" + android:summary="@string/battery_optimization_pref" + app:isPreferenceVisible="false" /> + <Preference android:key="prefAutoUpdateIntervall" android:summary="@string/feed_refresh_sum" android:title="@string/feed_refresh_title"/> |