Skip to content

Commit aac51fe

Browse files
authored
fix(android): Avoid crash on schedule if LocalNotifications are disabled (#2718)
1 parent 327ffc5 commit aac51fe

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

android/capacitor/src/main/java/com/getcapacitor/plugin/LocalNotifications.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,20 @@ public void schedule(PluginCall call) {
7373
return;
7474
}
7575
JSONArray ids = manager.schedule(call, localNotifications);
76-
notificationStorage.appendNotificationIds(localNotifications);
77-
JSObject result = new JSObject();
78-
JSArray jsArray = new JSArray();
79-
for (int i=0; i < ids.length(); i++) {
80-
try {
81-
JSObject notification = new JSObject().put("id", ids.getString(i));
82-
jsArray.put(notification);
83-
} catch (Exception ex) {
76+
if (ids != null) {
77+
notificationStorage.appendNotificationIds(localNotifications);
78+
JSObject result = new JSObject();
79+
JSArray jsArray = new JSArray();
80+
for (int i=0; i < ids.length(); i++) {
81+
try {
82+
JSObject notification = new JSObject().put("id", ids.getString(i));
83+
jsArray.put(notification);
84+
} catch (Exception ex) {
85+
}
8486
}
87+
result.put("notifications", jsArray);
88+
call.success(result);
8589
}
86-
result.put("notifications", jsArray);
87-
call.success(result);
8890
}
8991

9092
@PluginMethod()

0 commit comments

Comments
 (0)