I am trying to change the display name of a contact programmatically:
try { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) .withSelection(ContactsContract.CommonDataKinds.Phone._ID + " = ?", new String[] {contact_id}) .withValue(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "anything") .build()); ContentProviderResult[] result = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); } catch (Exception e) { Log.w("UpdateContact", e.getMessage()+""); for(StackTraceElement ste : e.getStackTrace()) { Log.w("UpdateContact", "\t" + ste.toString()); } Context ctx = getApplicationContext(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(ctx, "Update failed", duration); toast.show(); }
contact_id ContactsContract.CommonDataKinds.Phone._ID collected in the previous step
The code runs fine, but:
ContentProviderResult[] result is null- Contact name remains unchanged
I also experimented with Data.DISPLAY_NAME , but with the same effect.
I read the manual: http://developer.android.com/guide/topics/providers/contacts-provider.html , but I do not want to state my own intention.
Thanks.
androfan
source share