public List<Fri> lodcontacts(){ //得到客户端 ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if(cursor.moveToFirst()){ do { Fri fri = new Fri(); //联系人的姓名 String contactsName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); //联系人在数据库中的ID String pId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); Cursor phoneCursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + pId, null, null); String nuber=null; if(phoneCursor.moveToFirst()){ do { //电话号码 nuber=phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); }while (phoneCursor.moveToNext()); fri.name=contactsName; fri.phone=nuber; list.add(fri); } }while (cursor.moveToNext()); } return list; }
public class Fri { public String name; public String phone; }