From dbc5a2d54e2c43f9e812fe81823a1981534475d1 Mon Sep 17 00:00:00 2001 From: Dariusz Luksza Date: Fri, 11 May 2018 14:26:58 +0200 Subject: [PATCH] Fix ClassCastException while parsing fireDate ClassCastException was thrown on Android 8.1 while trying to schedule local notification. Use try-catch approach instead of relaying on the default parse value. --- .../RNFirebaseNotificationManager.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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 fccab1ee..a6d8a5ef 100644 --- a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java +++ b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java @@ -309,17 +309,19 @@ public class RNFirebaseNotificationManager { // 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) { + Long fireDate = -1L; + try { 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; + } catch (ClassCastException e) { + fireDate = schedule.getLong("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