I am having...mmm....difficulty let's say, updating the contact list.
I can add to it just fine, but when I go to update it, it processes,
but makes no change.  Here is my code:

        private void continueHandleEdit()
        {
                ArrayList<ContentProviderOperation> ops = new
ArrayList<ContentProviderOperation>();

        String displayName = firstNameEdit.getText().toString() + " "
+ lastNameEdit.getText().toString();
        String phoneNumber = phoneNumberEdit.getText().toString();

        
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
                     .withSelection(Data._ID + "=?", new String[] {mContactId})
                 .withValue(StructuredName.DISPLAY_NAME, displayName)
                     .withValue(Phone.NUMBER, phoneNumber)
                     .build());

        try
        {
                Log.d(TAG, "Applying: " + ops);

            ContentProviderResult[] res =
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

            if (res!=null && res[0]!=null)
            {
                int updated = res[0].count;


                Log.d(TAG, "Updated " + updated + " row(s)");
            }
            else
            {
                Log.e(TAG, "Contact not updated.");
            }

        }
        catch (RemoteException e)
        {
                Log.e(TAG, "RemoteEception caught: " + e.getMessage() +
"\nCause: " + e.getCause());
        }
        catch (OperationApplicationException e)
        {
                Log.e(TAG, "OperationApplicationEception caught: " +
e.getMessage() + "\nCause: " + e.getCause());
        }

        finish();
        }

Now the funny thing is that the log is showing the following:

[mType: 2, mUri: content://com.android.contacts/data, mSelection:
_id=?, mExpectedCount: null, mYieldAllowed: false, mValues:
data1=5446879999, mValuesBackReferences: null,
mSelectionArgsBackReferences: null]

Updated 1 row(s)

I know that the mContactId value holds the ID of the row as I verified
it. Also notice that the phone number is in there (5446879999) but
where is the display name? I know the variable held the right data as
I stepped through it and verified that.

What am I doing wrong?

 It shouldn't be this much of a pain to update a contact! Grrrrrr.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to