Android 調用系統聯系人界面的添加聯系人,添加已有聯系人,編輯和修改。


一、添加聯系人

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(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);


                                }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM