Andreas
Andreas

Reputation: 920

Pick a contact from the Contacts app; but only list contacts with email

I'm trying to select contacts depending on their information, it's working for phone numbers (as far as I can see); but when I try to pick contacts with only email it fails with the following error:

Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT typ=vnd.android.cursor.item/email_v2 }

Here's my code (or rather the important part):

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
if( SMS )
  intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
if( EMAIL )
  intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
startActivityForResult(intent, PICK_CONTACT);

Upvotes: 2

Views: 1479

Answers (1)

christiandeange
christiandeange

Reputation: 1175

I think you should be using Intent intent = new Intent(Intent.ACTION_PICK, uri), where uri is one of CommonDataKinds.Email.CONTENT_URI or CommonDataKinds.Phone.CONTENT_URI. That way, it'll display only contacts with an email or phone.

Upvotes: 5

Related Questions