How can I programmatically join 2 contacts in android?

大憨熊 提交于 2020-01-22 19:01:09

问题


I need to know if is it possible to join two or more contacts (in a programmatic way, using the Contacts android API or something).

For example, I have a contact "Axel Rose" with an email account and a phone number, and I've noticed that some apps like whatsapp, Facebook and Skype are creating new contact entries for Axel Rose, instead of merging the existing one.

I can join contacts using the "Join feature" from the phone, but is there a programmatic way?

Thanks in advance.
Cristian.


回答1:


You can use AggregationExceptions. See How to manual aggregate contacts ?

A good place to understand how contacts and aggregation works is Contacts Provider Documentation

Short summary:

The contacts that you see on your phonebook are the ones on the ContactsContract.Contacts table. The photo, phone, etc shown on the phonebook comes from different RawContacts entries. A contact can have one o several RawContacts.

A Contact happens to have several RawContact when the RawContacts share some data on common (name, phone number, email, etc). The union of this RawContacts into a single Contact is made by automatic aggregation rules (see Contact Basics docs).

You can't insert contacts on the ContactsContract.Contacts table. From the documentation:

Note: If you try to add a contact to the Contacts Provider with an insert(), you'll get an UnsupportedOperationException exception. If you try to update a column that's listed as "read-only," the update is ignored.



来源:https://stackoverflow.com/questions/11962848/how-can-i-programmatically-join-2-contacts-in-android

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