如何以编程方式在 android 中加入 2 个联系人? [英] How can I programmatically join 2 contacts in android?

查看:30
本文介绍了如何以编程方式在 android 中加入 2 个联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道是否可以加入两个或多个联系人(以编程方式,使用 Contacts android API 或其他方式).

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).

例如,我有一个带有电子邮件帐户和电话号码的联系人Axel Rose",我注意到一些应用程序,如 whatsapp、Facebook 和 Skype 正在为 Axel Rose 创建新的联系人条目,而不是合并现有的联系人条目.

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.

推荐答案

您可以使用 聚合异常.请参阅如何手动聚合联系人?

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

了解联系人和聚合如何工作的好地方是 联系提供者文档

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

简短摘要:

您在电话簿上看到的联系人是 ContactsContract.Contacts 表中的联系人.电话簿上显示的照片、电话等来自不同的 RawContacts 条目.一个联系人可以有一个或多个 RawContacts.

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.

当 RawContacts 共享一些公共数据(姓名、电话号码、电子邮件等)时,一个联系人碰巧有多个 RawContact.将此 RawContacts 合并为单个 Contact 是通过自动聚合规则进行的(参见 联系基础 文档).

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).

您无法在 ContactsContract.Contacts 表中插入联系人.来自文档:

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

注意:如果您尝试使用 insert() 将联系人添加到 Contacts Provider,您将收到 UnsupportedOperationException 异常.如果您尝试更新列为只读"的列,该更新将被忽略.

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.

这篇关于如何以编程方式在 android 中加入 2 个联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆