Widget - not always updating time.

This commit is contained in:
Pavol Franek 2020-03-16 19:41:09 +01:00
parent 97c9d31ef5
commit e85bbb35e1
1 changed files with 12 additions and 3 deletions

View File

@ -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 {