I'd like to pick an email from the contacts list. Picking a contact is not good enough, because a contact can have several emails.
Using the API demo, I managed to pick a contact, phone number and even an address. Example:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
// OR
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
// OR
intent.setType(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
BUT, when trying to pick an email
intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
I get activity not found exception.
Any idea on how to pick an email from the all the contacts' emails?
Thanks. Alik.
Update (2011/05/02): Found another way to pick things from the contacts but still the email picker is not registered to the intent.
Working:
new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI);
NOT working:
new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Email.CONTENT_URI);
Here's a sample bit of code to display all email addresses in the contact list to the user and allow them to select a single one (which is then put into an
EditText
with the id of R.id.youredittextid).Note: This is a rather inefficient way to do this, and will cause quite a delay if you have lots of contacts. But all the necessary code is here; customize as you see fit...
you have to use the following constant (not CONTENT_ITEM_TYPE):
An old thread but... this information could prove useful to someone. When you start an Intent with
Intent.ACTION_PICK
you are trying to invoke the "Contact Picker" activity, which is usually supplied by Contacts / Phonebook application.Latest version of vanilla (Google) Contacts app (Android 4.4.4) does have
Email.CONTENT_ITEM_TYPE
for mimetype in its intent filter, so it should respond to such intent, just as you made it. I am not sure but it seems that Contact Picker for older versions (ICS, JB) did not have this in its intent filters.In short, this intent should work on KK with vanilla Contacts installed, and should not work on older Android versions.
I haven't specifically tried to use a picker, but we loop through our cache of the contacts and find all the contact details with a MIME type of
Email.CONTENT_ITEM_TYPE
.Then we build a dialog to the let user pick which e-mail address they want to use, and we pass that e-mail address to the user's e-mail app, e.g.
Perfectly working: