diff --git a/framework/src/com/phonegap/ContactAccessorSdk3_4.java b/framework/src/com/phonegap/ContactAccessorSdk3_4.java index 42ff8fb8..079491d6 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk3_4.java +++ b/framework/src/com/phonegap/ContactAccessorSdk3_4.java @@ -106,20 +106,23 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { String searchTerm = ""; int limit = 1; boolean multiple = false; - try { - searchTerm = options.getString("filter"); + + if (options != null) { + searchTerm = options.optString("filter"); if (searchTerm.length()==0) { searchTerm = "%"; } else { searchTerm = "%" + searchTerm + "%"; } - multiple = options.getBoolean("multiple"); + multiple = options.optBoolean("multiple"); if (multiple) { - limit = options.getInt("limit"); + limit = options.optInt("limit"); + limit = limit > 0 ? limit : 1; } - } catch (JSONException e) { - Log.e(LOG_TAG, e.getMessage(), e); + } + else { + searchTerm = "%"; } ContentResolver cr = mApp.getContentResolver(); diff --git a/framework/src/com/phonegap/ContactAccessorSdk5.java b/framework/src/com/phonegap/ContactAccessorSdk5.java index a44827c6..f807ed31 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk5.java +++ b/framework/src/com/phonegap/ContactAccessorSdk5.java @@ -158,20 +158,23 @@ public class ContactAccessorSdk5 extends ContactAccessor { String searchTerm = ""; int limit = 1; boolean multiple = false; - try { - searchTerm = options.getString("filter"); + + if (options != null) { + searchTerm = options.optString("filter"); if (searchTerm.length()==0) { searchTerm = "%"; } else { searchTerm = "%" + searchTerm + "%"; } - multiple = options.getBoolean("multiple"); + multiple = options.optBoolean("multiple"); if (multiple) { - limit = options.getInt("limit"); + limit = options.optInt("limit"); + limit = limit > 0 ? limit : 1; } - } catch (JSONException e) { - Log.e(LOG_TAG, e.getMessage(), e); + } + else { + searchTerm = "%"; } //Log.d(LOG_TAG, "Search Term = " + searchTerm); @@ -339,8 +342,10 @@ public class ContactAccessorSdk5 extends ContactAccessor { } // Push the last contact into the contacts array - contacts.put(populateContact(contact, organizations, addresses, phones, - emails, ims, websites, relationships, photos)); + if (contacts.length() < limit) { + contacts.put(populateContact(contact, organizations, addresses, phones, + emails, ims, websites, relationships, photos)); + } } c.close(); diff --git a/framework/src/com/phonegap/ContactManager.java b/framework/src/com/phonegap/ContactManager.java index 5c6ffa97..5a79c37a 100755 --- a/framework/src/com/phonegap/ContactManager.java +++ b/framework/src/com/phonegap/ContactManager.java @@ -42,7 +42,7 @@ public class ContactManager extends Plugin { try { if (action.equals("search")) { - JSONArray res = contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1)); + JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1)); return new PluginResult(status, res, "navigator.service.contacts.cast"); } else if (action.equals("save")) {