查了好多,但是都不能用。不知道是什么原因,求大神告知。protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_01);
String string = "";
String disPlayName = "";
String phoneNumber = "";
TextView textView = (TextView) findViewById(R.id.textView);
ContentResolver cr = getContentResolver();// 获得ContentResolver实例
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_FILTER_URI,
null, null, null, null);
if (cursor.moveToFirst()) {
int displayNameColumn = cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
do {
disPlayName = cursor.getString(displayNameColumn);
int phoneCount = cursor
.getInt(cursor
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (phoneCount > 0) {
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, null, null, null);
if (phones.moveToFirst()) {
do {
phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
} while (phones.moveToNext());
}
}
string += disPlayName + ":" + phoneNumber + "\n";
} while (cursor.moveToNext());
}
cursor.close();
textView.setText(string);
}