如何在Android中添加联系人,如skype,whatsapp在原生联系人应用程序中?

Div*_*egi 8 java android

我正在创建一个联系人应用程序,但想要从我的应用程序添加联系人在本机Android联系人应用程序,就像Skype或WhatsApp.我需要扩展哪个类来实现此功能?

这是我想要创建的图片:

在此输入图像描述

小智 -3

好的,如果我明白你在寻找什么。您想要使用本机 Android 联系人列表。如果是这样,则步骤如下:

  1. 为结果而火的意图
  2. 接收结果意图,查找意图结果代码。
  3. 返回带有联系信息的游标
  4. 设置值。

一个简短的例子。火意图

Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);

//Receive the result
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
            case CONTACT_PICKER_RESULT:
                //deal with the resulting contact info. I built a separate util class for that.. but here is an example of the code.
                String[] projection = { ContactsContract.CommonDataKinds.Phone._ID,   ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                    ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Email.ADDRESS };
                Uri result = data.getData();
                String id = result.getLastPathSegment();
                ContentResolver contentResolver = getActivity().getContentResolver();

                //return cursor
                cur = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
                        ContactsContract.CommonDataKinds.Phone._ID + " like \"" + idUser + "%\"", null, null);
                //Use the cursor to return what you need.
        }
    }  
Run Code Online (Sandbox Code Playgroud)

下面是一个对光标的调用示例。请阅读 android 文档中有关联系人光标的更多信息。

email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
Run Code Online (Sandbox Code Playgroud)