Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android pick email intent

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);
like image 304
AlikElzin-kilaka Avatar asked May 02 '11 08:05

AlikElzin-kilaka


2 Answers

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();
like image 74
Dan J Avatar answered Oct 03 '22 02:10

Dan J


you have to use the following constant (not CONTENT_ITEM_TYPE):

intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_TYPE);
like image 40
rpaulin56 Avatar answered Oct 03 '22 04:10

rpaulin56