重复导入联系人时,android会把相同的联系人放在一个联系人名片夹中,通过编辑联系人界面可以看到。这样可能会带来编辑的bug,同时看着也不爽。
研究了下代码,原来,android导入时,会调用合并的功能。通过设置RawContacts.AGGREGATION_MODE可以达到导入不合并的效果。
RawContacts.AGGREGATION_MODE可以设置为:
RawContacts.AGGREGATION_MODE_DEFAULT;
RawContacts.AGGREGATION_MODE_IMMEDIATE;
RawContacts.AGGREGATION_MODE_SUSPENED;
RawContacts.AGGREGATION_MODE_DISABLED;
(详见android.provider.ContactsContract.java)
在导入联系人时insert的地方(frameworks/base/core/java/android/pim/vcard/VCardEntry.java : pushIntoContentResolver())加入
builder.withValue(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED);————————-android doc for RawContacts———————
Aggregation
As soon as a raw contact is inserted or whenever its constituent data changes, the provider will check if the raw contact matches other existing raw contacts and if so will aggregate it with those. The aggregation is reflected in the table by the change of the field, which is the reference to the aggregate contact.
Changes to the structured name, organization, phone number, email address, or nickname trigger a re-aggregation.
public static final int AGGREGATION_MODE_SUSPENDEDSince:
Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later. Changes to the raw contact will update the associated aggregate contact but will not result in any change in how the contact is aggregated. Similar to , but maintains a link to the corresponding aggregate.
This can be used to postpone aggregation until after a series of updates, for better performance and/or user experience.
Note that changing from to does not trigger an aggregation pass, but any subsequent change to the raw contact’s data will.
Constant Value: 2 (0x00000002)public static final int AGGREGATION_MODE_DISABLEDSince:
Aggregation mode: never aggregate this raw contact. The raw contact will not have a corresponding aggregate and therefore will not be included in query results.
For example, this mode can be used for a raw contact that is marked for deletion while waiting for the deletion to occur on the server side.
See AlsoConstant Value: 3 (0x00000003)