mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
canScheduleExactAlarms
This commit is contained in:
parent
11c4eeb661
commit
184c2a9b3f
2 changed files with 12 additions and 1 deletions
|
@ -23,6 +23,7 @@ import android.app.AlarmManager;
|
|||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.AlarmManagerCompat;
|
||||
|
@ -35,9 +36,18 @@ public class AlarmManagerCompatEx {
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean exact_alarms = prefs.getBoolean("exact_alarms", true);
|
||||
|
||||
if (exact_alarms)
|
||||
if (exact_alarms && canScheduleExactAlarms(context))
|
||||
AlarmManagerCompat.setExactAndAllowWhileIdle(am, type, trigger, pi);
|
||||
else
|
||||
AlarmManagerCompat.setAndAllowWhileIdle(am, type, trigger, pi);
|
||||
}
|
||||
|
||||
static boolean canScheduleExactAlarms(Context context) {
|
||||
if (Build.VERSION.SDK_INT < 31 /* S */)
|
||||
return true;
|
||||
else
|
||||
return true;
|
||||
//AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
//return am.canScheduleExactAlarms();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -833,6 +833,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
|
||||
setLastCleanup(prefs.getLong("last_cleanup", -1));
|
||||
|
||||
swExactAlarms.setEnabled(AlarmManagerCompatEx.canScheduleExactAlarms(getContext()));
|
||||
swTestIab.setVisibility(BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
||||
|
|
Loading…
Add table
Reference in a new issue