开发者

part of contact are repeated after each writing the same contact (Android 2.0+)

开发者 https://www.devze.com 2023-01-02 08:11 出处:网络
I met this problem at writing contacts by API for Android 2.0 or greater. Each time I write the same contact which already exist in my account (Google

I met this problem at writing contacts by API for Android 2.0 or greater. Each time I write the same contact which already exist in my account (Google account) I got some part of contact aggregated ok but other did not. For example fields like FN, N, ORG, TITLE always are in one copy but TEL, EMAIL, ADR are added extra so after 2nd writing the same contact I have 2 copy the same TEL or EMAIL. How to force API engine to not repeate existed data ?

Code:

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
                                .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType)
.withValue(ContactsContract.RawContacts.开发者_高级运维ACCOUNT_NAME, accountName)                       
.build());

...
// adding phone number

ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
            builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
            builder.withValue(ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
            builder.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneValue);
            builder.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType); // work/home
            builder.withValue(ContactsContract.CommonDataKinds.Phone.LABEL, phoneLabel);

            ops.add(builder.build());

...


try {
            contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
        } catch (Exception e) {
            //
}

I tried add: AGGREGATION_MODE on AGGREGATION_MODE_DISABLED. but it changed nothing.

I will glad for any hint in this case.

BR, Bogus


I think for an existing contact you either do an update, or delete rows for Data that exist for that contact, before doing an insert As I understand from the code you have, you are inserting stuff rather than updating.

0

精彩评论

暂无评论...
验证码 换一张
取 消