---
title: "Android 获取联系人"
author: "ThinkGoogle"
date: "2012-03-22T17:18:11Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2012-03-22T17:18:11Z"
id: 1461629
url: "https://thinkgoogle.iteye.com/blog/1461629"
---

Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT\_URI, null, null, null, null);  
            while(cursor.moveToNext())  
            {  
                //获取联系人ID  
                int contactId = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.\_ID));  
                //联系人姓名  
                String name  = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY\_NAME));  
                //联系人号码需要对另一URI进行查询  
                /\**  
                 * content://com.android.contacts/data/phone 等同于  
                 * ContactsContract.CommonDataKinds.Phone.CONTENT\_URI  
                 \*/  
                Cursor phones = this.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT\_URI  
                        , null, ContactsContract.CommonDataKinds.Phone.CONTACT\_ID +"="+contactId, null, null);  
                String phone = "";  
                while(phones.moveToNext())  
                {  
                    phone = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); //data1  
                }