Fallback to inexact alarm if exact is forbidden

This commit is contained in:
Ensar Sarajčić
2023-08-15 13:42:58 +02:00
parent 975e5543d1
commit 963ed146eb
2 changed files with 6 additions and 2 deletions

View File

@ -48,7 +48,11 @@ fun Context.scheduleNextAutomaticBackup() {
val pendingIntent = getAutomaticBackupIntent()
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
try {
AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, backupAtMillis, pendingIntent)
if (isUpsideDownCakePlus() && alarmManager.canScheduleExactAlarms()) {
AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, backupAtMillis, pendingIntent)
} else {
AlarmManagerCompat.setAndAllowWhileIdle(alarmManager, AlarmManager.RTC_WAKEUP, backupAtMillis, pendingIntent)
}
} catch (e: Exception) {
showErrorToast(e)
}