1
votes

I'm trying to open contacts and let user decide if he/she want to create or select a contact to use it on my app.

I need something like this: I need something like this

Where on the first option the user can add a new contact.

I tried the following code:

Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_TYPE);
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, CARREGA_CONTATOS);

But a got this error on Logcat (right after startActivityForResult):

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT_OR_EDIT typ=vnd.android.cursor.dir/contact (has extras) }

What I'm doing wrong?

EDIT:

I tried this code also with similar result:

Intent intent = new Intent(
    Intent.ACTION_INSERT_OR_EDIT,
    ContactsContract.Contacts.CONTENT_URI
);
startActivityForResult(intent, CARREGA_CONTATOS);

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT_OR_EDIT dat=content://com.android.contacts/contacts }

EDIT 2: Almost what I need:

Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, CARREGA_CONTATOS);

But this code opens this image, and the user must select "Contacts" before it goes to where I want. But this code opens this image

3
have you declared your activity in manifest? - Yurets

3 Answers

1
votes

Did you try this: https://stackoverflow.com/a/12722921/4029129

Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
startActivity(intent);
0
votes

The documentation seems to suggest using:

// Creates a new Intent to insert a contact
Intent intent = new Intent(Intents.Insert.ACTION);
// Sets the MIME type to match the Contacts Provider
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
0
votes

Usually you have to add the default category intent.addCategory(Intent.CATEGORY_DEFAULT) to make it match an an action.