I try to sync android contacts. I want to use first and family name to identify a contact and update it with the raw_id, but I don’t know how to search for family name and surname. I looked at the sample files, but there’s only a description to search (and sync) with the raw_id!
Share
The “family” name as a separate field isn’t part of the Contacts table.
Rows in the Contacts table are generated automatically by the provider. In general, one Contacts row aggregates one or more raw contacts in ContactsContract.RawContacts. Each raw contact has a StructuredName row that contains the family name.
To do the search you describe, search ContactsContract.CommonDataKinds.StructuredName on FAMILY_NAME and GIVEN_NAME. Provide a projection that includes LOOKUP_KEY, which is a “permanent” link to the row in ContactsContract.Contacts that you want.
Alas, this is based only on the documentation. LOOKUP_KEY is supposed to be part of the columns available to a query on StructuredName, but I’ve seen other cases where the documentation didn’t match the implementation. Apparently, the developers sometimes include a list of implemented column names, but don’t actually seem to implement returning them.
Also, the original response used getContentResolver(). Please use CursorLoader instead, whenever possible.