This code snippet works for me cursor = contentResolver.query(Data.CONTENT_URI, null, Data.LOOKUP_KEY + "='" + lookupKey + "'", null, null);
cursor.moveToFirst(); int columnIndex = cursor.getColumnIndexOrThrow(StructuredName.DISPLAY_NAME); Log.i(TAG, "DisplayName: " + cursor.getString(columnIndex)); contactInfo.setContactDisplayName(cursor.getString(columnIndex)); columnIndex = cursor.getColumnIndexOrThrow(StructuredName.GIVEN_NAME); Log.i(TAG, "GivenName: " + cursor.getString(columnIndex)); contactInfo.setContactGivenName(cursor.getString(columnIndex)); columnIndex = cursor.getColumnIndexOrThrow(StructuredName.FAMILY_NAME); Log.i(TAG, "FamilyName: " + cursor.getString(columnIndex)); contactInfo.setContactFamilyName(cursor.getString(columnIndex)); cursor.close(); Hope it helps On 30 Lug, 23:37, j <jac...@gmail.com> wrote: > Thanks for the reply. I agree the API doc is very ambiguous. > > On Jul 30, 12:39 am, William Ferguson <william.ferguson...@gmail.com> > wrote: > > > You appear to be using a combination of Android 1.5 and Android 2.0 > > mechanisms. > > Ie passing Android 2.0 constants to an Android 1.5 mechanism. > > > Android 1.5 > > > > Uri uri = Phone.CONTENT_URI; > > > Phone.CONTACT_ID, > > > Phone.DISPLAY_NAME, > > > Phone.NUMBER, > > > Phone.TYPE, Phone.LABEL, > > > Android 2.0 > > > > ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, > > > But I could be wrong. The ContactsContract provider is pretty unclear > > IMHO. > > I think you'll gain some mileage > > from:http://stackoverflow.com/questions/1721279/how-to-read-contacts-on-an... > > > On Jul 30, 7:47 am, j <jac...@gmail.com> wrote: > > > > While iterating through my contacts database, the firstName > > > (GIVEN_NAME) always returns an integer (0, 1, 2, ... 7) while the > > > lastName (FAMILY_NAME) always returns null. I am running on HTC > > > Incredible. What am I doing wrong? > > > > Uri uri = Phone.CONTENT_URI; > > > String[] projection = new String[] { > > > Phone.CONTACT_ID, > > > Phone.DISPLAY_NAME, > > > Phone.NUMBER, > > > Phone.TYPE, Phone.LABEL, > > > ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, > > > ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME > > > > }; > > > > Cursor managedCursor = mContext.getContentResolver() > > > .query(uri, projection, null, null, null); > > > if(managedCursor == null) { > > > Log.w(LOG_TAG, "managedCursor null"); > > > return null; > > > } > > > > while(managedCursor.moveToNext()) { > > > > long contactId = managedCursor.getLong( > > > > managedCursor.getColumnIndex(Phone.CONTACT_ID)); > > > String name = managedCursor.getString( > > > > managedCursor.getColumnIndex(Phone.DISPLAY_NAME)); > > > > String firstName = managedCursor.getString( > > > > managedCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));// > > > getFirstNameFromId(contactId); > > > Log.d(LOG_TAG, "firstName: "+ firstName); > > > String lastName = managedCursor.getString( > > > > managedCursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));// > > > getLastNameFromId(contactId); > > > Log.d(LOG_TAG, "lastName: "+ lastName); > > > > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en