Android 调用系统联系人界面的添加联系人,添加已有联系人,编辑和修改。

本文详细介绍了如何在Android设备上进行联系人的添加、编辑、删除等操作,包括向已存在的联系人添加新电话号码的方法,并提供了实现这些功能的具体代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、添加联系人
Intent addIntent = new Intent(Intent.ACTION_INSERT,Uri.withAppendedPath(Uri.parse("content://com.android.contacts"), "contacts"));
            addIntent.setType("vnd.android.cursor.dir/person");
            addIntent.setType("vnd.android.cursor.dir/contact");
            addIntent.setType("vnd.android.cursor.dir/raw_contact");
addIntent.putExtra(ContactsContract.Intents.Insert.NAME,number);
名称: addIntent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, numberForNewConstant);
电话:
            startActivity(addIntent);

二、添加到已有联系人

复制代码
LogUtil.logI("================btnAddToOladContact=====================");
            Intent oldConstantIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
            oldConstantIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
            oldConstantIntent.putExtra(ContactsContract.Intents.Insert.PHONE, numberForNewConstant);
            oldConstantIntent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, 3);
            startActivity(oldConstantIntent);
            if(oldConstantIntent.resolveActivity(getActivity().getPackageManager()) != null){
                LogUtil.logI("================btnAddToOladContact=========yes============");
                startActivity(oldConstantIntent);
            }else
                LogUtil.logI("================btnAddToOladContact=========no============");
复制代码

 

三、编辑联系人

Intent editIntent = new Intent(Intent.ACTION_EDIT,Uri.parse("content://com.android.contacts/contacts/"+cb.getContactId()));
                        startActivity(editIntent);

 

四、删除联系人

复制代码
//*************删除联系人******************
                                Uri deleteUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, cb.getContactId());
                                Uri lookupUri = ContactsContract.Contacts.getLookupUri(ContactsDetailActivity.this.getContentResolver(), deleteUri);
                                if (lookupUri != Uri.EMPTY) {
                                    int del = ContactsDetailActivity.this.getContentResolver().delete(deleteUri, null, null);
                                    LogUtil.logI("==========popupMenu============del:"+del);


                                }
复制代码
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值