dimanche 3 mai 2015

How to open contacts and let user decide if he/she want to create or select one contact

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=http://ift.tt/1dYDtGX (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

Aucun commentaire:

Enregistrer un commentaire