1

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

Megacan
  • 2,510
  • 3
  • 20
  • 31
  • possible duplicate of [Logcat says "invalid column data1"](http://stackoverflow.com/questions/17255434/logcat-says-invalid-column-data1) – Selvin Oct 04 '13 at 14:43
  • I'm not sure if this is the cause of your problem, but in your `onACtivityResult()` you're not checking to make sure that the request code matches `PICK_CONTACT_REQUEST`. Other than that, the code looks the same. – Prmths Oct 04 '13 at 14:46
  • I didn't want to copy all the code in the example, but yes I'm checking that the requestcode matches. The problem is building the query with a projection for the Phone.NUMBER column. – Megacan Oct 04 '13 at 14:48
  • @Selvin: The solution for that question was to put the Phone.NUMBER in the projection which I did, it still doesn't work (the OP states that making that change didn't work either). I'm wondering why the example on the documentation doesn't work. – Megacan Oct 04 '13 at 14:51
  • no, no ... solution is to add some column from Contants table (fx.: `Contacts.DISPLAY_NAME`)... ContentProvider for contancts is, well, messy. data for this provider is stored in few tables ... it automaticaly join other tables if there is a column from such table ... in your case(i think) it had to join at least 3 tables: lookups, contacts, phones(i'm not sue because it was a long time ago i've been looking into the source) – Selvin Oct 04 '13 at 14:55
  • ...or you can also try translate lookupUri to contactUri: `getContentResolver().query(ContactsContract.Contacts.lookupContact(getContentResolver(), contactUri), projection, null, null, null);` – Selvin Oct 04 '13 at 15:02
  • I ended up using a contact picker I saw in another answer. The Contacts Provider is too messy. : ( – Megacan Oct 07 '13 at 09:50

1 Answers1

-1

I use ContactsContract.PhoneLookup.NORMALIZED_NUMBER when searching a phone number, and this work well. It is a column name error.

lynn8570
  • 1,685
  • 1
  • 14
  • 24