public void btnOtherReadContacts(View v){
//内容提供者的解析器对象
ContentResolver resolver = getContentResolver();
//这个循环的是data表
Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
StringBuffer sb = new StringBuffer();
while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
sb.append("姓名 : "+name+" 电话 : "+phone);
}
System.out.println("--- : "+sb.toString());
//内容提供者的解析器对象
ContentResolver resolver = getContentResolver();
//这个循环的是data表
Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
StringBuffer sb = new StringBuffer();
while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
sb.append("姓名 : "+name+" 电话 : "+phone);
}
System.out.println("--- : "+sb.toString());
}
//记住清单文件里 要加读取权限
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>