diff --git a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java index 5e258231..654de394 100644 --- a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java @@ -34,6 +34,7 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis public static final int AVAILABILITY_OUT_OF_OFFICE = 4; public static final int AVAILABILITY_WORKING_ELSEWHERE = 5; + public static final String calendarAlarmAction = "ALARM_FOR_CALENDAR"; static List calendarsCache = null; static List calendarEventsCache = null; @@ -65,6 +66,11 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis checkForRules(context); armOrRearmTimer(); } + else if(intent.getAction().equalsIgnoreCase(calendarAlarmAction)) + { + Miscellaneous.logEvent("i", "AlarmReceiver", "Received alarm for calendar receiver.", 5); + routineAtAlarm(); + } } private static void checkForRules(Context context) @@ -268,16 +274,6 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis return calendarEventsCache; } - public static class AlarmReceiver extends BroadcastReceiver - { - @Override - public void onReceive(Context context, Intent intent) - { - Miscellaneous.logEvent("i", "AlarmReceiver", "Received alarm for calendar receiver.", 5); - routineAtAlarm(); - } - } - protected static void routineAtAlarm() { checkForRules(Miscellaneous.getAnyContext()); @@ -296,8 +292,9 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis { alarmManager = (AlarmManager) Miscellaneous.getAnyContext().getSystemService(Context.ALARM_SERVICE); - Intent i = new Intent(Miscellaneous.getAnyContext(), AlarmReceiver.class); - pi = PendingIntent.getBroadcast(Miscellaneous.getAnyContext(), 0, i, 0); + Intent intent = new Intent(Miscellaneous.getAnyContext(), CalendarReceiver.class); + intent.setAction(calendarAlarmAction); + pi = PendingIntent.getBroadcast(AutomationService.getInstance(), 0, intent, 0); } } else @@ -341,7 +338,9 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis } Miscellaneous.logEvent("i", "armOrRearmTimer()", "Setting calendar alarm for " + nextWakeup.toString(), 5); - alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextWakeup.getTimeInMillis(), pi); + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextWakeup.getTimeInMillis(), pi); + + //alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextWakeup.getTimeInMillis(), pi); } } else