2

i want to update existing contact details. first i want to display phone default contact interface with existing contact information relevant to one contact id. And then i want to update contact details like phone number, name , email etc.

public static void updateContactInPhone(Activity activity,Contact contact) {

    try {
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

        ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
        .withSelection(Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'", new String[]{contact.getContactId()})
        .withValue(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "new name")
        .build());

        ContentProviderResult[] result = activity.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 = activity;
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(ctx, "Update failed", duration);
        toast.show();
    }
}

i tried to update name according to this bt i didn't get any result. please help.

user3800832
  • 421
  • 2
  • 8
  • 21

0 Answers0