Uri uri;
// email query
uri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI,
Uri.encode(mKeyword));
cursor = resolver.query(uri, EMAIL_SEARCH_PROJECTION, null, null, null);
if (cursor != null) {
try {
while (cursor.moveToNext()) {
long id = cursor.getLong(ContactSummary.CONTACT_SUMMARY_COL_ID);
if (!excludeIds.contains(id) && !contactIds.contains(id)) {
contactIds.add(id);
}
}
} finally {
cursor.close();
cursor = null;
}
}
// phone number start to query the phone only if the number
// looks like a phone
if (Telephony.isPossiblePhoneNum(mKeyword)) {
if (Config.DEBUG) {
Log.v(TAG, mKeyword + " is a number");
}
uri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,
Uri.encode(mKeyword));
cursor = resolver.query(uri, PHONE_SEARCH_PROJECTION, null, null, null);
if (cursor != null) {
try {
while (cursor.moveToNext()) {
long id = cursor.getLong(ContactSummary.CONTACT_SUMMARY_COL_ID);
if (!excludeIds.contains(id) && !contactIds.contains(id)) {
contactIds.add(id);
}
}
} finally {
cursor.close();
cursor = null;
}
}
}
private static final String[] EMAIL_SEARCH_PROJECTION = new String[] {
Email.CONTACT_ID
};
private static final String[] PHONE_SEARCH_PROJECTION = new String[] {
Phone.CONTACT_ID
};