I am trying to change the contact name and last name programmatically. The code snippet I used to complete the job is as follows:
operations.add( ContentProviderOperation.newUpdate( Data.CONTENT_URI ) .withSelection( RawContacts._ID + "=?", new String[] { String.valueOf( mSmartphoneContactKey) } ) .withValue( ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, mContactName.getEditableText().toString() ) .withValue( ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, mContactLastName.getEditableText().toString() ) .build() );
mSmartphoneContactKey populated with data contained in a column
ContactsContract.Contacts._ID
which sits in my projection array when I read contacts using a content provider.
The problem is that for some contacts, the first and last name does not change, but the type of phone changes. In fact, I have no information about the reason. Any advice is appreciated.
I read further the documentation that uses the data table that I should use. I changed the code as below ... still not working
operations.add( ContentProviderOperation.newUpdate( Data.CONTENT_URI ) .withSelection( Data._ID + " = ? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", new String[] { String.valueOf( mSmartphoneContactId ) } ) .withValue( ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, mContactName.getEditableText().toString() ) .withValue( ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, mContactLastName.getEditableText().toString() ) .build() );
Please help me!
Madblack
source share