zoukankan      html  css  js  c++  java
  • 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);
    
    
                                    }
  • 相关阅读:
    Mac下ssh连接远程服务器时自动断开问题
    解决php中json_decode的异常JSON_ERROR_CTRL_CHAR (json_last_error = 3)
    如何写.gitignore只包含指定的文件扩展名
    python操作mysql数据库
    php数组函数
    Python中字符串切片操作
    Python实现字符串反转的几种方法
    每个Android开发者都应该了解的资源列表
    Android Studio 入门指南
    一个优秀的Android应用从建项目开始
  • 原文地址:https://www.cnblogs.com/longhs/p/5435398.html
Copyright © 2011-2022 走看看