我要启动一个联系人选择器,获取结果并获取联系人的姓名和电话号码。我正在关注此链接上的示例。
它看起来很容易。启动意图:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
并在 onActivityResult 上得到结果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri contactUri = data.getData();
String[] projection = {Phone.NUMBER};
Cursor cursor = getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
// Do something with the phone number...
}
}
但是当我做 getContentResolver().query(...) 时,它会抛出一个异常:
10-04 15:24:57.390: E/AndroidRuntime(14303): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/3218idc91bbd08f828c0.2327ig:104894074019203432183/314 flg=0x1 }} to activity {com.smv.vtickets/com.smv.vtickets.activities.MainActivity}: java.lang.IllegalArgumentException: Invalid column data1
它告诉我列 data1 无效:
java.lang.IllegalArgumentException: Invalid column data1
这不应该工作吗?
编辑:我仔细研究了联系人提供者的工作方式。这有点乱,长话短说,我最终使用了这个:Android联系人选择器