I have written the code for simple update.I am able to insert and delete the data from the the contacts of my AVD but when I want to update the data,its not updating.
here is my sample code:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
String rawContactInsertIndex = (Integer.toString(ops.size()));
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection( Data.CONTACT_ID + "=?" , new String[] { rawContactInsertIndex })
.withValue(StructuredName.DISPLAY_NAME, firstname)
.withValue(StructuredName.FAMILY_NAME, lastname)
.withValue(StructuredName.GIVEN_NAME, firstname)
can any one help? I am stuck here.
To start, your
.withSelection(Data.CONTACT_ID + "=?", new String[]{rawContactInsertIndex}is going to perform an update on all data columns where theData.CONTACT_IDcolumn has the value0. This includes phone numbers, addresses etc. etc.Fortunately, there’s no such contact apparently, because you’d f-ck that contact up royally.
To start, you should fetch the correct
CONTACT_IDand do some work on your selection, i.e. do a selection on theData.MIME_TYPEalso.Also, are you sure you should be updating on
CONTACT_ID? Consider usingRAW_CONTACT_ID.