Prompt for battery optimization (#6362)
This commit is contained in:
parent
d8d94878a2
commit
0b3e664057
|
@ -10,6 +10,7 @@
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||||
|
|
||||||
<supports-screens
|
<supports-screens
|
||||||
android:anyDensity="true"
|
android:anyDensity="true"
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package de.danoeh.antennapod.fragment.preferences;
|
package de.danoeh.antennapod.fragment.preferences;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
@ -17,10 +22,13 @@ import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static android.content.Context.POWER_SERVICE;
|
||||||
|
|
||||||
|
|
||||||
public class NetworkPreferencesFragment extends PreferenceFragmentCompat
|
public class NetworkPreferencesFragment extends PreferenceFragmentCompat
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private static final String PREF_SCREEN_AUTODL = "prefAutoDownloadSettings";
|
private static final String PREF_SCREEN_AUTODL = "prefAutoDownloadSettings";
|
||||||
|
private static final String PREF_BATTERY_OPTIMIZATION = "prefBatteryOptimization";
|
||||||
private static final String PREF_PROXY = "prefProxy";
|
private static final String PREF_PROXY = "prefProxy";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,6 +67,20 @@ public class NetworkPreferencesFragment extends PreferenceFragmentCompat
|
||||||
new FeedRefreshIntervalDialog(getContext()).show();
|
new FeedRefreshIntervalDialog(getContext()).show();
|
||||||
return true;
|
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)
|
findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS)
|
||||||
.setOnPreferenceChangeListener(
|
.setOnPreferenceChangeListener(
|
||||||
|
|
|
@ -2,8 +2,14 @@
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:numberpicker="http://schemas.android.com/apk/de.danoeh.antennapod"
|
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">
|
xmlns:search="http://schemas.android.com/apk/com.bytehamster.lib.preferencesearch">
|
||||||
<PreferenceCategory android:title="@string/automation">
|
<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
|
<Preference
|
||||||
android:key="prefAutoUpdateIntervall"
|
android:key="prefAutoUpdateIntervall"
|
||||||
android:summary="@string/feed_refresh_sum"
|
android:summary="@string/feed_refresh_sum"
|
||||||
|
|
|
@ -418,6 +418,8 @@
|
||||||
<item quantity="one">Every hour</item>
|
<item quantity="one">Every hour</item>
|
||||||
<item quantity="other">Every %d hours</item>
|
<item quantity="other">Every %d hours</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
<string name="battery_optimization_pref_title">Battery Optimization</string>
|
||||||
|
<string name="battery_optimization_pref">For more reliable automatic downloads and automatic refresh, exclude AntennaPod from battery optimization. Tap to add an exception for AntennaPod.</string>
|
||||||
<string name="pref_followQueue_title">Continuous Playback</string>
|
<string name="pref_followQueue_title">Continuous Playback</string>
|
||||||
<string name="pref_pauseOnHeadsetDisconnect_title">Headphones or Bluetooth disconnect</string>
|
<string name="pref_pauseOnHeadsetDisconnect_title">Headphones or Bluetooth disconnect</string>
|
||||||
<string name="pref_unpauseOnHeadsetReconnect_title">Headphones Reconnect</string>
|
<string name="pref_unpauseOnHeadsetReconnect_title">Headphones Reconnect</string>
|
||||||
|
|
Loading…
Reference in New Issue