decades
decades

Reputation: 837

Android: How to start contacts for eMail?

this Intent opens the Contacts, containing entries with address information only:

Intent getContactIntent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI);

Now I was trying to use this pattern to filter for contacts containing an eMail:

Intent getContactIntent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Email.CONTENT_URI);

But this excepts (no action_pick for intent or so)

How can I achieve that?

Upvotes: 2

Views: 2250

Answers (2)

Femi
Femi

Reputation: 64700

Currently you can not with the default Contacts app: the default Contacts app registers this Intent filter (see line 165 in https://android.googlesource.com/platform/packages/apps/Contacts/+/master/AndroidManifest.xml#165):

<intent-filter>
                 <action android:name="android.intent.action.PICK" />
                 <category android:name="android.intent.category.DEFAULT" />
                 <data android:mimeType="vnd.android.cursor.dir/contact" />
                 <data android:mimeType="vnd.android.cursor.dir/person" />
                 <data android:mimeType="vnd.android.cursor.dir/phone_v2" />
                 <data android:mimeType="vnd.android.cursor.dir/phone" />
                 <data android:mimeType="vnd.android.cursor.dir/postal-address_v2" />
                 <data android:mimeType="vnd.android.cursor.dir/postal-address" />
             </intent-filter>

So it is able to respond to the postal address ACTION_PICK intents, but not to email address ACTION_PICK intents.

If you want to do the email address pick you will need to create your own Activity that gets a Cursor from the Contacts provider that only displays users with email addresses and shows that in a ListView for the user to pick.

Upvotes: 3

Shoo Limberger
Shoo Limberger

Reputation: 386

Try this:

      public void readcontact(){
            try {
                Intent intent = new Intent(Intent.ACTION_PICK,  ContactsContract.Contacts.CONTENT_URI);
                intent.setType("vnd.android.cursor.dir/email");
                startActivityForResult(intent, PICK_CONTACT);
            } catch (Exception e) {
                    e.printStackTrace();
              }
        }

Upvotes: 0

Related Questions