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:
Try if you use Kotlin
fun Fragment.saveContact(name: String?, phone: String?) {
if (name != null && phone != null) {
val addContactIntent = Intent(Intent.ACTION_INSERT)
addContactIntent.type = ContactsContract.Contacts.CONTENT_TYPE
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, name)
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE, phone)
startActivity(addContactIntent)
}
}