Android 调用系统联系人界面(添加联系人,添加已有联系人,编辑和修改)
程序员文章站
2023-12-01 13:16:16
一、添加联系人
intent addintent = new intent(intent.action_insert,uri.withappendedpath(u...
一、添加联系人
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); }
以上所述是小编给大家介绍的android 调用系统联系人界面(添加联系人,添加已有联系人,编辑和修改),希望对大家有所帮助