android — 获取通讯录联系人电话_雪松_新浪博客

Manifest.xml

<uses-permission

android:name=”android.permission.READ_CONTACTS”

/>

代码:

  

ContentResolver cr = getContentResolver();

  

Cursor cursor =

cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null,

null);

  

  

while(cursor.moveToNext()){

  

 //获取联系人名字

  

 int nameFieldColumnIndex =

cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);

  

 String contact =

cursor.getString(nameFieldColumnIndex);

  

 //取得电话号码

  

 String ContactId =

cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

  

 Cursor phone =

cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,

ContactsContract.CommonDataKinds.Phone.CONTACT_ID+”=”+ContactId,null,null);

  

 

  

 while(phone.moveToNext()){//获取联系人所有电话信息 

手机、单位电话 ..

  

  String

PhoneNumber =

phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

  

  tellNum +=

(contact + “:” + PhoneNumber +”\n”);

  

 }

  

}

  

cursor.close();

来源URL:http://blog.sina.com.cn/s/blog_86ef2c1d0100z53t.html