Search code examples
androidandroid-intentcontactsandroid-contactsintentfilter

Pick contact from Contacts list and select a specific email for that contact


I know that if I create an Intent like this:

val contactPickerIntent = Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
        startActivityForResult(contactPickerIntent, request_code)

I will be able to pick a contact from my Contacts list.

And if i set the intent like this:

val contactPickerIntent = Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI)

I will be able to go into the selected contact details (from within the contacts app) but i won't be able to pick anything from it.

The thing is I need to open the contact's details and select one of it's email addresses, in case he has more than one, and pick it.

Is there a way to do that?


Solution

  • You can change your picker from a Contact picker to an Email picker:

    Intent contacts = new Intent(Intent.ACTION_PICK, CommonDataKinds.Email.CONTENT_URI); // Note the Email!
    startActivityForResult(contacts, PICK_CONTACTS);
    

    See: https://developer.android.com/guide/components/intents-common#Contacts