@@ -222,15 +222,17 @@ private void listCalendars() {
222222 cordova .getThreadPool ().execute (new Runnable () {
223223 @ Override
224224 public void run () {
225- JSONArray jsonObject = new JSONArray ();
226225 try {
227- jsonObject = Calendar .this .getCalendarAccessor ().getActiveCalendars ();
226+ JSONArray activeCalendars = Calendar .this .getCalendarAccessor ().getActiveCalendars ();
227+ if (activeCalendars == null ) {
228+ activeCalendars = new JSONArray ();
229+ }
230+ PluginResult res = new PluginResult (PluginResult .Status .OK , activeCalendars );
231+ callback .sendPluginResult (res );
228232 } catch (JSONException e ) {
229233 System .err .println ("Exception: " + e .getMessage ());
230234 callback .error (e .getMessage ());
231235 }
232- PluginResult res = new PluginResult (PluginResult .Status .OK , jsonObject );
233- callback .sendPluginResult (res );
234236 }
235237 });
236238 }
@@ -469,7 +471,7 @@ public void run() {
469471 private static String getPossibleNullString (String param , JSONObject from ) {
470472 return from .isNull (param ) || "null" .equals (from .optString (param )) ? null : from .optString (param );
471473 }
472-
474+
473475 private void listEventsInRange (JSONArray args ) {
474476 // note that if the dev didn't call requestReadPermission before calling this method and calendarPermissionGranted returns false,
475477 // the app will ask permission and this method needs to be invoked again (done for backward compat).
@@ -479,7 +481,7 @@ private void listEventsInRange(JSONArray args) {
479481 return ;
480482 }
481483 try {
482- final JSONObject jsonFilter = args .getJSONObject (0 );
484+ final JSONObject jsonFilter = args .getJSONObject (0 );
483485 JSONArray result = new JSONArray ();
484486 long input_start_date = jsonFilter .optLong ("startTime" );
485487 long input_end_date = jsonFilter .optLong ("endTime" );
@@ -490,7 +492,7 @@ private void listEventsInRange(JSONArray args) {
490492 } else {
491493 l_eventUri = Uri .parse ("content://calendar/instances/when/" + String .valueOf (input_start_date ) + "/" + String .valueOf (input_end_date ));
492494 }
493-
495+
494496 cordova .getThreadPool ().execute (new Runnable () {
495497 @ Override
496498 public void run () {
@@ -557,7 +559,7 @@ public void run() {
557559 callback .error (e .getMessage ());
558560 }
559561 }
560-
562+
561563 public void onActivityResult (int requestCode , int resultCode , Intent data ) {
562564 if (requestCode == RESULT_CODE_CREATE ) {
563565 if (resultCode == Activity .RESULT_OK || resultCode == Activity .RESULT_CANCELED ) {
0 commit comments