When updating a ContactsContract.Data
StructuredName
row for a RawContact
, my code sets the DISPLAY_NAME
column with a value provided by the user. It also updates the first, middle, last with values provided by the user.
When fetching the contact DISPLAY_NAME
back from ContactsContract.Contacts
, the display name provided to the RawContact
is ignored and, instead, Android has fabricated one based on the StructuredName
name parts.
Is there a way to tell ContactsContract
to use the display name provided?
For example, consider that the following are written to a StructuredName
row:
DISPLAY_NAME: F L
GIVEN_NAME: F
MIDDLE_NAME: X
LAST_NAME: L
In this case, I would expect the aggregate contact display name to be "F L". However, it will be "F X L".
Here is the code to write a StructureName row, where the values being set to each column are member variables:
protected void prepareUpdate (ArrayList<ContentProviderOperation> ops)
{
String where = ContactsContract.Data._ID + " = " + dataId;
ContentProviderOperation.Builder builder;
builder = ContentProviderOperation.newUpdate (ContactsContract.Data.CONTENT_URI);
builder.withSelection (where, null);
builder.withValue (ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, displayName);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, givenName);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, familyName);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.PREFIX, prefix);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME, middleName);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.SUFFIX, suffix);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.PHONETIC_FAMILY_NAME, phoneticFamilyName);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.PHONETIC_MIDDLE_NAME, phoneticMiddleName);
builder.withValue (ContactsContract.CommonDataKinds.StructuredName.PHONETIC_GIVEN_NAME, phoneticGivenName);
ops.add (builder.build());
}
Here's the code that executes the "ops":
ContentResolver resolver = context.getContentResolver();
ContentProviderResult[] results = resolver.applyBatch(ContactsContract.AUTHORITY, ops);
And, here's the code to fetch the aggregate contact's display name:
public static ContactData fetchContact (Cursor cursor)
{
String name = cursor.getString (cursor.getColumnIndex (ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
... do something with the feteched data ...
}
If Android is ignoring the display name provided by the user, what is the point of that column?