Insert a new contact intent

后端 未结 9 1004
陌清茗
陌清茗 2020-11-30 23:02

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:



        
9条回答
  •  隐瞒了意图╮
    2020-11-30 23:32

    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)
        }
    }
    

提交回复
热议问题