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);
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.
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_STREAM, "Some text");
Builder builder = new Builder(this);
builder.setTitle("Choose email");
builder.setItems(emailAddressesArray, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
String address = emailAddresses.get(emailAddressesArray[which]);
sLog.user("User selected e-mail: " + address);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{address});
startExternalActivity(emailIntent);
}
});
builder.show();
you have to use the following constant (not CONTENT_ITEM_TYPE):
intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_TYPE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With