3
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.clear();

    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
            .withSelection(Data._ID + "=?", new String[]{String.valueOf(id)})
            .withValue(Email.DATA, "somebody1@android.com")
            .build());

    try 
    {
        context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
    }

The logs don't show me anything. But the email is not updated. Does anyone know why?

The ops converted to string is as follows:

[mType: 2, mUri: content://com.android.contacts/data, mSelection: _id=?, mExpectedCount: null, mYieldAllowed: false, mValues: data1=somebody1@android.com, mValuesBackReferences: null, mSelectionArgsBackReferences: null]
Developer Android
  • 577
  • 3
  • 5
  • 21
  • have you tried using Log.d('tag',VALUEasSTRING); to check your values? – daniel Dec 15 '12 at 02:25
  • Which value do you mean? The id? If so yes – Developer Android Dec 15 '12 at 02:28
  • actually all the values, but sounds like you already tried this – daniel Dec 15 '12 at 02:29
  • I'm having this issue too. No matter what I do, it doesn't seem to update. My `ContentProviderOperation` looks exactly the same. – Jonah Jan 30 '14 at 05:26
  • Where is id coming from ? My guess is it could be something else like a raw contact ID, meaning that the selection would be empty and thus no update would be performed. @Jonah – desseim Feb 04 '14 at 19:43
  • @desseim I didn't see your comment before. I'm getting it from `Entity.DATA_ID` when querying in the first place. I've started my own question. http://stackoverflow.com/q/21594024/278899 – Jonah Feb 06 '14 at 04:30

2 Answers2

0

First, you have a try without a catch, which may explain why you don't see any error in the logs.

Second, from what I can see in the documentation, I think you should better write it this way:

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.clear();

ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
        .withSelection(ContactsContract.Data.CONTACT_ID + "=?", 
                       new String[] {String.valueOf(id)})
        .withValue(ContactsContract.CommonDataKinds.Email.DATA, "somebody1@android.com")
        .build());

try {
    context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
    e.printStackTrace();
}
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
-1

Try use inside withValue not string, but array of strings.

.withValue(ContactsContract.CommonDataKinds.Email.DATA, emails)

where

String[] emails = {"Email Name<somebody1@android.com>"};
Tapa Save
  • 4,769
  • 5
  • 32
  • 54