try using setExactAndAllowWhileIdle at Android 6+ for scheduling notifications

This commit is contained in:
tibbi 2017-11-09 20:23:22 +01:00
parent 96ce109aa6
commit 89615acf89

View file

@ -96,10 +96,10 @@ fun Context.scheduleEventIn(notifTS: Long, event: Event) {
val pendingIntent = getNotificationIntent(applicationContext, event)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
if (isKitkatPlus()) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
when {
isMarshmallowPlus() -> alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
isKitkatPlus() -> alarmManager.setExact(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
else -> alarmManager.set(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
}
}