簡體   English   中英

如何在Android中添加聯系人,例如Skype,本機聯系人應用中的whatsapp?

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

我正在創建聯系人應用程序,但想從我的應用程序(如Skype或WhatsApp)中在本地android聯系人應用程序中添加聯系人。 我需要擴展什么類來實現此功能?

這正是我要創建的圖片:

在此處輸入圖片說明

好吧,如果我了解您的需求。 您要使用本機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.
        }
    }  

這是對游標的示例調用。 請在android文檔中閱讀有關聯系人游標的更多信息。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM