From d193c6b688850bf72ba321b3238b39f463ae38be Mon Sep 17 00:00:00 2001 From: Liam Heneghan Date: Mon, 30 Apr 2018 14:48:13 +1200 Subject: [PATCH] + Fix Android rescheduled notifications firing immediately --- .../RNFirebaseNotificationManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 11ffc218..494ecc9e 100644 --- a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java +++ b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java @@ -657,7 +657,21 @@ public class RNFirebaseNotificationManager { String notificationId = notification.getString("notificationId"); Bundle schedule = notification.getBundle("schedule"); - Double fireDate = schedule.getDouble("fireDate"); + // fireDate is stored in the Bundle as Long after notifications are rescheduled. + // This would lead to a fireDate of 0.0 when trying to extract a Double from the bundle. + // Instead always try extract a Long + Long fireDate = schedule.getLong("fireDate", -1); + if (fireDate == -1) { + fireDate = (long) schedule.getDouble("fireDate", -1); + if (fireDate == -1) { + if (promise == null) { + Log.e(TAG, "Missing schedule information"); + } else { + promise.reject("notification/schedule_notification_error", "Missing fireDate information"); + } + return; + } + } // Scheduled alarms are cleared on restart // We store them so that they can be re-scheduled when the phone restarts in RNFirebaseNotificationsRebootReceiver