For one of my apps, I need the user to select one of his existing contacts or to create a new one. Picking one is clearly easy to do with the following code:
i = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(i, PICK_CONTACT_REQUEST );
Now I want to create a new contact. I tried to use that code but it doesn't trigger the activity result:
i = new Intent(Intent.ACTION_INSERT);
i.setType(Contacts.CONTENT_TYPE);
startActivityForResult(i, PICK_CONTACT_REQUEST);
The above code will start the contact adding form. Then when I validate it, it just asks me to open the contact list and the onActivityResult method is never triggered.
Could you help me to make it working ?
I read on some boards that this wasn't possible, and I had to create my own contact adding form. Could you confirm that ?
EDIT: Problem solved. Check my answer.
If you already have details for the contact, such as a phone number or email address, you can insert them into the intent as extended data. For a key value, use the appropriate constant from Intents.Insert. The contacts app displays the data in its insert screen, allowing users to make further edits and additions.
Once you've created the Intent, send it by calling startActivity().
Note : import "intents" of "ContactsContract"
Finally found a solution, I'm sharing it with you. That's only a fix for Android version above 4.0.3 and sup. It doesn't work on 4.0 to 4.0.2.
Try if you use Kotlin
You can choose whether you want to add the contact automatically, or open the add contact activity with pre-filled data:
this code might help you.