1. 加入读取联系人信息的权限
<uses-permissionandroid:name="android.permission.READ_CONTACTS"/>
content://com.android.contacts/contacts操作的数据是联系人信息Uri
content://com.android.contacts/data/phones联系人电话Uri
content://com.android.contacts/data/emails联系人EmailUri
读取联系人信息
2. 部分代码:
Cursorcursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
while (cursor.moveToNext()) {
String contactId =cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name =cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Cursor phones =getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID+" = "+ contactId,
null, null);
while (phones.moveToNext()) {
String phoneNumber =phones.getString(phones.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.i("RongActivity", "phoneNumber="+phoneNumber);
}
phones.close();
Cursor emails =getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID+ " = " + contactId,
null,null);
while (emails.moveToNext()) {
// This would allow you get severalemail addresses
String emailAddress =emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
Log.i("RongActivity","emailAddress="+ emailAddress);
}
emails.close();
}
cursor.close();
--转自