From 3bcf90277fdd0939155e95fddc4d98579f5ff38c Mon Sep 17 00:00:00 2001 From: jens Date: Sun, 31 Dec 2023 15:54:24 +0100 Subject: [PATCH] calendar trigger --- .../receivers/CalendarReceiver.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) 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 5e25823..654de39 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