简体   繁体   English

如何在Android中添加联系人,例如Skype,本机联系人应用中的whatsapp?

[英]How to add contact in Android like skype, whatsapp in native contact app?

I am creating a contact app but want to add contacts in the native android contact app from my app just like Skype or WhatsApp. 我正在创建联系人应用程序,但想从我的应用程序(如Skype或WhatsApp)中在本地android联系人应用程序中添加联系人。 What class would I need to extend to implement this functionality? 我需要扩展什么类来实现此功能?

Here is the picture of exactly what I want to create: 这正是我要创建的图片:

在此处输入图片说明

Ok if I understand what you are looking for. 好吧,如果我了解您的需求。 You want to use the native Android contact list.. If so then here are the steps: 您要使用本机Android联系人列表。如果是这样,请按照以下步骤操作:

  1. fire intent for result 为结果着火
  2. receive the intent for result looking for the intent result code. 接收结果意图,查找意图结果代码。
  3. return a cursor with the contact information 返回带有联系信息的光标
  4. set the values. 设置值。

A short example. 一个简短的例子。 fire intent 开火意图

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.
        }
    }  

Here is an example call to the cursor. 这是对游标的示例调用。 Please read some more about the contact cursor in the android docs. 请在android文档中阅读有关联系人游标的更多信息。

email = emailCursor.getString(emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM