mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Fixing query so that it uses wildcards
This commit is contained in:
parent
a427b8cead
commit
2098436a2c
File diff suppressed because it is too large
Load Diff
@ -24,6 +24,7 @@ import org.json.JSONObject;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.provider.Contacts.ContactMethods;
|
import android.provider.Contacts.ContactMethods;
|
||||||
import android.provider.Contacts.ContactMethodsColumns;
|
import android.provider.Contacts.ContactMethodsColumns;
|
||||||
import android.provider.Contacts.Organizations;
|
import android.provider.Contacts.Organizations;
|
||||||
@ -61,7 +62,12 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
boolean multiple = true;
|
boolean multiple = true;
|
||||||
try {
|
try {
|
||||||
searchTerm = options.getString("filter");
|
searchTerm = options.getString("filter");
|
||||||
if (searchTerm.length()==0) searchTerm = "%";
|
if (searchTerm.length()==0) {
|
||||||
|
searchTerm = "%";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
searchTerm = "%" + searchTerm + "%";
|
||||||
|
}
|
||||||
multiple = options.getBoolean("multiple");
|
multiple = options.getBoolean("multiple");
|
||||||
if (multiple) {
|
if (multiple) {
|
||||||
limit = options.getInt("limit");
|
limit = options.getInt("limit");
|
||||||
@ -75,9 +81,15 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
JSONObject contact;
|
JSONObject contact;
|
||||||
|
|
||||||
ContentResolver cr = mApp.getContentResolver();
|
ContentResolver cr = mApp.getContentResolver();
|
||||||
Cursor cur = cr.query(People.CONTENT_URI,
|
|
||||||
null, null, null, null);
|
|
||||||
|
|
||||||
|
// Right now we are just querying the displayName
|
||||||
|
Cursor cur = cr.query(People.CONTENT_URI,
|
||||||
|
null,
|
||||||
|
People.DISPLAY_NAME + " LIKE ?",
|
||||||
|
new String[] {searchTerm},
|
||||||
|
People.DISPLAY_NAME + " ASC");
|
||||||
|
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
while (cur.moveToNext() && pos < limit) {
|
while (cur.moveToNext() && pos < limit) {
|
||||||
contact = new JSONObject();
|
contact = new JSONObject();
|
||||||
|
@ -63,19 +63,23 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
boolean multiple = true;
|
boolean multiple = true;
|
||||||
try {
|
try {
|
||||||
searchTerm = options.getString("filter");
|
searchTerm = options.getString("filter");
|
||||||
if (searchTerm.length()==0) searchTerm = "%";
|
if (searchTerm.length()==0) {
|
||||||
|
searchTerm = "%";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
searchTerm = "%" + searchTerm + "%";
|
||||||
|
}
|
||||||
multiple = options.getBoolean("multiple");
|
multiple = options.getBoolean("multiple");
|
||||||
if (multiple) {
|
if (multiple) {
|
||||||
limit = options.getInt("limit");
|
limit = options.getInt("limit");
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Limit = " + limit);
|
|
||||||
System.out.println("Multiple = " + multiple);
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(LOG_TAG, e.getMessage(), e);
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
// Get a cursor by creating the query.
|
// Get a cursor by creating the query.
|
||||||
ContentResolver cr = mApp.getContentResolver();
|
ContentResolver cr = mApp.getContentResolver();
|
||||||
|
|
||||||
|
// Right now we are just querying the displayName
|
||||||
Cursor cursor = cr.query(
|
Cursor cursor = cr.query(
|
||||||
ContactsContract.Contacts.CONTENT_URI,
|
ContactsContract.Contacts.CONTENT_URI,
|
||||||
new String[] {ContactsContract.Contacts._ID, ContactsContract.Contacts.HAS_PHONE_NUMBER, ContactsContract.Contacts.DISPLAY_NAME},
|
new String[] {ContactsContract.Contacts._ID, ContactsContract.Contacts.HAS_PHONE_NUMBER, ContactsContract.Contacts.DISPLAY_NAME},
|
||||||
|
Loading…
Reference in New Issue
Block a user