I am trying to select a phone number from the global address book (corporate account). I would like to use my own collector / API because I do not want to ask the user for login credentials. I came across the ContactsContract.Directory API. However, I could not find any examples of how to use them. I tried:
private static final String[] PEOPLE_PROJECTION = new String[] {
ContactsContract.Directory._ID,
ContactsContract.Directory.DISPLAY_NAME,
};
StringBuilder buffer = null;
String[] args = null;
if (constraint != null) {
buffer = new StringBuilder();
buffer.append("UPPER(");
buffer.append(Phone.DISPLAY_NAME);
buffer.append(") GLOB ?");
args = new String[] { constraint.toString().toUpperCase() + "*" };
}
Cursor c = getContentResolver().query(ContactsContract.Directory.CONTENT_URI, PEOPLE_PROJECTION, buffer == null ? null : buffer.toString(), args, null);
But c always returns null. Please note that I am trying to recover only DISPLAY_NAME here, as I am not sure how to restore the phone number. Thank you for your help.
source
share