diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt index 9d2b5a98..af0f8278 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt @@ -6,18 +6,17 @@ import android.appwidget.AppWidgetManager import android.content.ComponentName import android.content.Context import android.content.Intent -import android.content.SharedPreferences import android.media.AudioAttributes import android.media.AudioManager import android.media.AudioManager.STREAM_ALARM import android.net.Uri +import android.os.Build import android.os.PowerManager import android.text.SpannableString import android.text.style.RelativeSizeSpan import android.widget.Toast import androidx.core.app.AlarmManagerCompat import androidx.core.app.NotificationCompat -import androidx.preference.PreferenceManager import com.simplemobiletools.clock.R import com.simplemobiletools.clock.activities.ReminderActivity import com.simplemobiletools.clock.activities.SnoozeReminderActivity @@ -38,6 +37,7 @@ import com.simplemobiletools.commons.helpers.isOreoPlus import java.util.* import kotlin.math.pow + val Context.config: Config get() = Config.newInstance(applicationContext) val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext) @@ -168,7 +168,16 @@ fun Context.scheduleNextWidgetUpdate() { val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager val triggerAtMillis = System.currentTimeMillis() + getMSTillNextMinute() - alarmManager.setExact(AlarmManager.RTC, triggerAtMillis, pendingIntent) + + when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> { + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC, triggerAtMillis, pendingIntent) + } + + else -> { + alarmManager.setExact(AlarmManager.RTC, triggerAtMillis, pendingIntent) //MAYBE RTC_WAKEUP + } + } } fun Context.getFormattedTime(passedSeconds: Int, showSeconds: Boolean, makeAmPmSmaller: Boolean): SpannableString {