Android - Update a contact

前端 未结 3 403
我寻月下人不归
我寻月下人不归 2020-12-01 05:30

I\'m trying to update a contact of my phone book directly from my app. I\'m able to add and delete the contacts but the update just does nothing!

After the insert or

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 06:16

    For Updating contact you need to have both contactId and RawContact id... so while updating add this also as a value in where clause/selection args..

    something like this..

    ArrayList ops = new ArrayList();
    
            //------------------------------------------------------ Names
    
            ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                    .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
                    .withValue(ContactsContract.Data.MIMETYPE,
                            ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.PREFIX, data.getTitle())
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.SUFFIX, data.getSuffix())
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, data.getFirstName())
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME, data.getMiddleName())
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, data.getSuffix())
                            .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, data.getFirstName()+" "+data.getMiddleName()).build());
    

提交回复
热议问题