diff --git a/app/src/main/java/com/jens/automation2/receivers/DateTimeListener.java b/app/src/main/java/com/jens/automation2/receivers/DateTimeListener.java index 75f49e78..be4079ab 100644 --- a/app/src/main/java/com/jens/automation2/receivers/DateTimeListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/DateTimeListener.java @@ -29,7 +29,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis { private static AutomationService automationServiceRef; private static AlarmManager centralAlarmManagerInstance; - private static boolean alarmListenerActive=false; + private static boolean alarmListenerActive = false; private static ArrayList alarmCandidates = new ArrayList<>(); private static ArrayList requestCodeList = new ArrayList(); static PendingIntent alarmPendingIntent = null; @@ -250,7 +250,10 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis else alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); - centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + centralAlarmManagerInstance.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent); + else + centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent); SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm:ss"); Calendar calendar = Calendar.getInstance();