I have this code to get the first and last name of contacts:
uri = ContactsContract.Data.CONTENT_URI;
Cursor curName = getContentResolver().query(uri, null, ContactsContract.Data.CONTACT_ID +" = "+ contactId, null, null);
if (curName.getCount() > 0){
curName.moveToFirst();
String nameGiven = curName.getString(curName.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
String nameFamily = curName.getString(curName.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
log += nameGiven + ", " + nameFamily + ": ";
}
I have only one contact, so I do not need a loop. On device 2.3.5, it works fine, returning the correct names. But on device 4.0.4, it returns null for both fields, but if you request a display name, it provides it correctly.
What could be the problem?
source
share