No projection array gets Contact name


#1

When I followed the book and called

String [] queryFields = new String[]{ContactsContract.Contacts.DISPLAY_NAME};
Cursor c = getActivity().getContentResolver().query(contactUri, queryFields, null, null, null);
if(c.getCount() == 0){
     c.close();
     return;
}

//never gets here

c.moveToFirst();
mCrime.setSuspect(c.getString(0));
c.close();

Cursor.getCount() would always have a value of ‘zero’. So instead of the string array (queryFields) I passed in null to the call to query() and boom Contact name’s for everyone :wink: :

Cursor c = getActivity().getContentResolver().query(contactUri, null, null, null, null);
if(c.getCount() == 0){
     c.close();
     return;
}

c.moveToFirst();
int colIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
mCrime.setSuspect(c.getString(colIndex));
c.close();

Hope it helps…
Devon
Developing with ADT; running on HTC Desire w/ICS loaded