How to update existing contact?

前端 未结 6 1896
闹比i
闹比i 2020-12-15 05:26

I have one existing contact, I need to add a work address to that existing contact. I am using the following code, but it\'s not working.

String selectPhone          


        
6条回答
  •  眼角桃花
    2020-12-15 06:04

    //Sorry for my bad english // It seems that in the first post you forgot to add the MimeType in operation.

    String selectPhone = Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "='" + 
                        ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE +  "'" ; 
                    String[] phoneArgs = new String[]{String.valueOf(rawContactId)}; 
                    ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) 
                        .withSelection(selectPhone, phoneArgs) 
                        .withValue(ContactsContract.CommonDataKinds.StructuredPostal.TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK)
                        .withValue(ContactsContract.CommonDataKinds.StructuredPostal.STREET, STREET)
                        .withValue(ContactsContract.CommonDataKinds.StructuredPostal.CITY, CITY) 
                        .withValue(ContactsContract.CommonDataKinds.StructuredPostal.REGION, REGION)
                        .withValue(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE, POSTCODE) 
                        .withValue(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, POSTCODE) 
    

    **

    //Just add this line .withValue(Data.MIMETYPE, "vnd.android.cursor.item/postal-address_v2")

    **

         .build());
    this.context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
    

    Please check this and let me know the result

提交回复
热议问题