Skip to content

Instantly share code, notes, and snippets.

@mstefanko
Created March 28, 2011 13:30
Show Gist options
  • Save mstefanko/890450 to your computer and use it in GitHub Desktop.
Save mstefanko/890450 to your computer and use it in GitHub Desktop.
Retrieving contact details
//Basic contact information stored in Contacts table with detailed information stored in individual //tables for normalization. In Android 2.0 to query the base contact records the URI to query is stored //in ContactsContract.Contacts.CONTENT_URI.
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
//TODO:Query phone here.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment