diff --git a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java index 948ba9bd..185dc4d5 100644 --- a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java +++ b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java @@ -36,6 +36,7 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import java.util.Map; @@ -357,6 +358,21 @@ public class RNFirebaseNotificationManager { notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (schedule.containsKey("repeatInterval")) { + // If fireDate you specify is in the past, the alarm triggers immediately. + // So we need to adjust the time for correct operation. + if (fireDate < System.currentTimeMillis()) { + Calendar newFireDate = Calendar.getInstance(); + Calendar currentFireDate = Calendar.getInstance(); + currentFireDate.setTimeInMillis(fireDate); + + newFireDate.add(Calendar.DATE, 1); + newFireDate.set(Calendar.HOUR_OF_DAY, currentFireDate.get(Calendar.HOUR_OF_DAY)); + newFireDate.set(Calendar.MINUTE, currentFireDate.get(Calendar.MINUTE)); + newFireDate.set(Calendar.SECOND, currentFireDate.get(Calendar.SECOND)); + + fireDate = newFireDate.getTimeInMillis(); + } + Long interval = null; switch (schedule.getString("repeatInterval")) { case "minute":