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 pendingIntent = getNotificationIntent(applicationContext, event)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
if (isKitkatPlus()) { when {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent) isMarshmallowPlus() -> alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
} else { isKitkatPlus() -> alarmManager.setExact(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
alarmManager.set(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent) else -> alarmManager.set(AlarmManager.RTC_WAKEUP, notifTS, pendingIntent)
} }
} }