Skip to content

Commit

Permalink
Fix ClassCastException while parsing fireDate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dluksza committed May 11, 2018
1 parent f3806da commit dbc5a2d
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,19 @@ private void scheduleNotification(Bundle notification, @Nullable Promise promise
// 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
Expand Down

0 comments on commit dbc5a2d

Please sign in to comment.