Android contacts aggregation process

不羁岁月 提交于 2021-02-08 02:57:26

问题


I'm unable to find detailed information about the aggregation process in Android's contacts. I'm aware of the ContactsContract.Contacts -> ContactsContract.RawContacts -> ContactsContract.Data structure (as described on http://developer.android.com/guide/topics/providers/contacts-provider.html), and that a Contact consists of Raw Contacts, which are grouped together through one Contact_ID.

What I specifically want to know is: under what circumstances are Raw Contacts grouped into one Contact?

I found this question and answer - specifically the last option:

At least one of the two raw contacts is missing the name altogether and they are sharing a phone number, an email address or a nickname (for example, Bob Parr [incredible@android.com] = incredible@android.com).

I tried this out, however, it doesn't seem to work. I want to know if I can add a Raw Contact to the local contacts and set only the ACCOUNT_TYPE, ACCOUNT_NAME and phone or emailaddress, and if this will be automatically aggregrated with a raw contact for whom this phone number or emailaddress already exists. So for example:

(ContactsContract.Contacts.)_ID (Similar to ContactsContract.RawContacts.Contact_ID): 1188300 consists of:

  • Raw Contact ID 20905
    MIMETYPE = \email_v2
    ACCOUNT_TYPE = com.google
    NAME = Example Test
    EMAIL = test@gmail.com
  • Raw Contact ID 20897
    MIMETYPE = \phone_v2
    ACCOUNT_TYPE = com.google
    NAME = Example Test
    EMAIL = 123456

After adding the following:

  • Raw Contact
    MIMETYPE = \email_v2
    ACCOUNT_TYPE = com.exampleApp EMAIL = test@gmail.com

will this result into: (ContactsContract.Contacts.)_ID: 1188300 consisting of:

  • Raw Contact ID 20905
    MIMETYPE = \email_v2
    ACCOUNT_TYPE = com.google
    NAME = Example Test
    EMAIL = test@gmail.com
  • Raw Contact ID 20897
    MIMETYPE = \phone_v2
    ACCOUNT_TYPE = com.google
    NAME = Example Test
    EMAIL = 123456

  • Raw Contact ID 20899 (or whatever number)
    MIMETYPE = \email_v2
    ACCOUNT_TYPE = com.exampleApp
    NAME = Example Test
    EMAIL = test@gmail.com


回答1:


The contacts aggregation is handled by the ContactAggregator2.java

What is does is match every raw contact with other raw contacts, the aggregations is done based on a score generated by RawContactMatcher

The file contains a little explanation, but you can check the score assigned for different parameters and also the matching scores (EXACT, CONSERVATIVE and APPROXIMATE).

Example for Name-

/**
 * Name matching scores: a matrix by name type vs. candidate lookup type.
 * For example, if the name type is "full name" while we are looking for a
 * "full name", the score may be 99. If we are looking for a "nickname" but
 * find "first name", the score may be 50 (see specific scores defined
 * below.)
 * <p>
 * For approximate matching, we have a range of scores, let's say 40-70.  Depending one how
 * similar the two strings are, the score will be somewhere between 40 and 70, with the exact
 * match producing the score of 70.  The score may also be 0 if the similarity (distance)
 * between the strings is below the threshold.
 * <p>
 * We use a string matching algorithm, which is particularly suited for
 * name matching. See {@link NameDistance}.
 */

If you want two contacts to be aggregated(Joined) just add an entry in http://developer.android.com/reference/android/provider/ContactsContract.AggregationExceptions.html with type as TYPE_KEEP_TOGETHER



来源:https://stackoverflow.com/questions/33150632/android-contacts-aggregation-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!