From aac51fefc9e66599fa5b02f585d28c1566a07976 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 7 Apr 2020 16:43:26 +0200 Subject: [PATCH] fix(android): Avoid crash on schedule if LocalNotifications are disabled (#2718) --- .../plugin/LocalNotifications.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java index 24a44167f..e607c57c2 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java @@ -73,18 +73,20 @@ public void schedule(PluginCall call) { return; } JSONArray ids = manager.schedule(call, localNotifications); - notificationStorage.appendNotificationIds(localNotifications); - JSObject result = new JSObject(); - JSArray jsArray = new JSArray(); - for (int i=0; i < ids.length(); i++) { - try { - JSObject notification = new JSObject().put("id", ids.getString(i)); - jsArray.put(notification); - } catch (Exception ex) { + if (ids != null) { + notificationStorage.appendNotificationIds(localNotifications); + JSObject result = new JSObject(); + JSArray jsArray = new JSArray(); + for (int i=0; i < ids.length(); i++) { + try { + JSObject notification = new JSObject().put("id", ids.getString(i)); + jsArray.put(notification); + } catch (Exception ex) { + } } + result.put("notifications", jsArray); + call.success(result); } - result.put("notifications", jsArray); - call.success(result); } @PluginMethod()