我有一个发送到联系人活动的意图,然后主活动在此回调中获取结果。问题是该列始终为-1。话虽这么说,我如何获得联系人姓名?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == RESULT_OK) {
Uri contactUri = data.getData();
String[] projection = {Phone.NUMBER};
Cursor cursor = getContentResolver().query(contactUri,
projection, null, null, null);
if (cursor.moveToFirst()) {
int column = cursor.getColumnIndex(
ContactsContract.PhoneLookup.DISPLAY_NAME);
if (column >= 0) {
String name = cursor.getString(column);
addString(name);
} else {
addString("Could Not Get User Name");
}
}
}
}
}