From cd9031e58d3ca3747f7680faeba43e3609653f4c Mon Sep 17 00:00:00 2001 From: F0079 Date: Sat, 4 Jul 2026 22:02:24 +0200 Subject: [PATCH 1/2] add start date to cron like scheduler --- .../LocalNotificationManager.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java index 0b826a546..02599ae01 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java @@ -332,6 +332,21 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi } PendingIntent pendingIntent = PendingIntent.getBroadcast(context, request.getId(), notificationIntent, flags); + // Cron like scheduler + DateMatch on = schedule.getOn(); + if (on != null) { + Date startDate = schedule.getAt() == null + ? new Date() + : schedule.getAt(); + long trigger = on.nextTrigger(startDate); + notificationIntent.putExtra(TimedNotificationPublisher.CRON_KEY, on.toMatchString()); + pendingIntent = PendingIntent.getBroadcast(context, request.getId(), notificationIntent, flags); + setExactIfPossible(alarmManager, schedule, trigger, pendingIntent); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + Logger.debug(Logger.tags("LN"), "notification " + request.getId() + " will next fire at " + sdf.format(new Date(trigger))); + return; + } + // Schedule at specific time (with repeating support) Date at = schedule.getAt(); if (at != null) { @@ -356,18 +371,6 @@ private void triggerScheduledNotification(Notification notification, LocalNotifi long startTime = new Date().getTime() + everyInterval; alarmManager.setRepeating(AlarmManager.RTC, startTime, everyInterval, pendingIntent); } - return; - } - - // Cron like scheduler - DateMatch on = schedule.getOn(); - if (on != null) { - long trigger = on.nextTrigger(new Date()); - notificationIntent.putExtra(TimedNotificationPublisher.CRON_KEY, on.toMatchString()); - pendingIntent = PendingIntent.getBroadcast(context, request.getId(), notificationIntent, flags); - setExactIfPossible(alarmManager, schedule, trigger, pendingIntent); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - Logger.debug(Logger.tags("LN"), "notification " + request.getId() + " will next fire at " + sdf.format(new Date(trigger))); } } From 61c5e095c6033c952c0c13881a7cd7d6950e06c0 Mon Sep 17 00:00:00 2001 From: F0079 Date: Thu, 9 Jul 2026 22:37:01 +0200 Subject: [PATCH 2/2] update documentation --- local-notifications/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local-notifications/README.md b/local-notifications/README.md index c88bde1a3..8d732af65 100644 --- a/local-notifications/README.md +++ b/local-notifications/README.md @@ -495,7 +495,7 @@ Use either `at`, `on`, or `every` to schedule notifications. | **`at`** | Date | Schedule a notification at a specific date and time. | 1.0.0 | | **`repeats`** | boolean | Repeat delivery of this notification at the date and time specified by `at`. Only available for iOS and Android. | 1.0.0 | | **`allowWhileIdle`** | boolean | Allow this notification to fire while in [Doze](https://developer.android.com/training/monitoring-device-state/doze-standby) Note that these notifications can only fire [once per 9 minutes, per app](https://developer.android.com/training/monitoring-device-state/doze-standby#assessing_your_app). | 1.0.0 | -| **`on`** | ScheduleOn | Schedule a notification on particular interval(s). This is similar to scheduling [cron](https://en.wikipedia.org/wiki/Cron) jobs. Only available for iOS and Android. | 1.0.0 | +| **`on`** | ScheduleOn | Schedule a notification on particular interval(s). This is similar to scheduling [cron](https://en.wikipedia.org/wiki/Cron) jobs. Only available for iOS and Android. When the `at` property is defined additionally, then the first notification is postponed to that specific date and time (Android only). | 1.0.0 | | **`every`** | ScheduleEvery | Schedule a notification on a particular interval. | 1.0.0 | | **`count`** | number | Limit the number times a notification is delivered by the interval specified by `every`. | 1.0.0 |