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

Reply via email to