Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion local-notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ Use either `at`, `on`, or `every` to schedule notifications.
| **`at`** | <code><a href="#date">Date</a></code> | <a href="#schedule">Schedule</a> a notification at a specific date and time. | 1.0.0 |
| **`repeats`** | <code>boolean</code> | Repeat delivery of this notification at the date and time specified by `at`. Only available for iOS and Android. | 1.0.0 |
| **`allowWhileIdle`** | <code>boolean</code> | 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`** | <code><a href="#scheduleon">ScheduleOn</a></code> | <a href="#schedule">Schedule</a> 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`** | <code><a href="#scheduleon">ScheduleOn</a></code> | <a href="#schedule">Schedule</a> 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`** | <code><a href="#scheduleevery">ScheduleEvery</a></code> | <a href="#schedule">Schedule</a> a notification on a particular interval. | 1.0.0 |
| **`count`** | <code>number</code> | Limit the number times a notification is delivered by the interval specified by `every`. | 1.0.0 |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)));
}
}

Expand Down