get contact info from android contact picker
Posted
by ng93
on Stack Overflow
See other posts from Stack Overflow
or by ng93
Published on 2010-06-15T11:05:51Z
Indexed on
2010/06/15
11:12 UTC
Read the original article
Hit count: 796
hi im trying to call the contact picker, get the persons name, phone and e-mail into strings and send them to another activity using an intent. So far this works
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 1);
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
intent.putExtra("name", name);
startActivityForResult(intent, 0);
}
}
}
but if i add in:
String number = c.getString(c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
it force closes
maybe theres another way to get their number?
thanks for help, ng93
© Stack Overflow or respective owner