use AlarmManagerCompat for scheduling event reminders

This commit is contained in:
tibbi 2018-03-30 11:10:05 +02:00
parent 134fd58c1a
commit 16e10a07de
1 changed files with 2 additions and 8 deletions

View File

@ -14,6 +14,7 @@ import android.media.AudioManager
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.CalendarContract import android.provider.CalendarContract
import android.support.v4.app.AlarmManagerCompat
import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationCompat
import android.view.Gravity import android.view.Gravity
import android.view.View import android.view.View
@ -32,9 +33,7 @@ import com.simplemobiletools.calendar.receivers.CalDAVSyncReceiver
import com.simplemobiletools.calendar.receivers.NotificationReceiver import com.simplemobiletools.calendar.receivers.NotificationReceiver
import com.simplemobiletools.calendar.services.SnoozeService import com.simplemobiletools.calendar.services.SnoozeService
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isKitkatPlus
import com.simplemobiletools.commons.helpers.isLollipopPlus import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.commons.helpers.isOreoPlus
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
@ -110,12 +109,7 @@ 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
AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager, 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)
}
} }
fun Context.cancelNotification(id: Int) { fun Context.cancelNotification(id: Int) {