0

I am currently selecting a contact from the phones contact book, and then saving the name with the following code:

int nameColumn = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String name = cursor.getString(nameColumn)

I am wondering if there is a way to get the email of the contact in a similar fashion, something like CommonDataKinds.Phone.EMAIL

Dr Mido
  • 2,414
  • 4
  • 32
  • 72

1 Answers1

0

selecting a contact from the phones contact book

by that you mean you're using:

Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT)

to have the user pick a contact from the device's contacts app?

If so, you can slightly change the picker code to become an email-picker instead:

Intent intent = new Intent(Intent.ACTION_PICK, Email.CONTENT_URI);  
startActivityForResult(intent, PICK_EMAIL);

Then in your onActivityResult:

Uri emailUri = data.getData();
Cursor cursor = getContentResolver().query(emailUri, null, null, null, null);
String email = cursor.getString(cursor.getColumnIndex(Email.DATA)); // get the email itself

DatabaseUtils.dumpCursor(cursor); // dump the cursor so you can see the fields and data you can access
cursor.close();
marmor
  • 27,641
  • 11
  • 107
  • 150