I'm to launch a Contact Picker, get the result and obtain the name and phone number of the contact. I'm following the example on this link.
It looks easy enough. Launch the intent:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
And get the result on the 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...
}
}
But when I do getContentResolver().query(...) it throws an exception:
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
It tells me that the column data1 in invalid:
java.lang.IllegalArgumentException: Invalid column data1
Shouldn't this work?
EDIT: I took a closer look at how the Contact Provider work. It's a little messy so, long story short, I ended up using this: Android contact picker