From d77d80e39ead7990cbff62e3fb04a0ab57859307 Mon Sep 17 00:00:00 2001 From: Doug Keen Date: Fri, 28 Oct 2016 07:07:01 -0700 Subject: [PATCH] Use appropriate AlarmManager methods for different API levels --- app/src/main/java/com/dougkeen/bart/model/Departure.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/dougkeen/bart/model/Departure.java b/app/src/main/java/com/dougkeen/bart/model/Departure.java index f3b13ee..7a08ecf 100644 --- a/app/src/main/java/com/dougkeen/bart/model/Departure.java +++ b/app/src/main/java/com/dougkeen/bart/model/Departure.java @@ -6,6 +6,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.Color; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.ColorInt; @@ -595,7 +596,13 @@ public class Departure implements Parcelable, Comparable { long alarmTime = getAlarmClockTime(); - alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent); + } else { + alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent); + } if (Log.isLoggable(Constants.TAG, Log.VERBOSE)) Log.v(Constants.TAG,