startActivityForResult(new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI), 0)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
ContentResolver reContentResolverol = getContentResolver()
Uri contactData = data.getData()
Cursor cursor = managedQuery(contactData, null, null, null, null)
cursor.moveToFirst()
String username = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))
String contactId = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID))
Cursor phone = reContentResolverol.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
+ contactId, null, null)
while (phone.moveToNext()) {
String usernumber = phone
.getString(phone
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))
usernumber = usernumber.replaceAll("-", "")
Log.d("测试-姓名",username)
Log.d("测试-号码",usernumber)
}
}
}