安卓联系人查询
我在查询电话簿联系人时遇到问题。我需要做的是获取输入了电话和电子邮件或特定类型的联系人列表。
基本上是这样的:
public static final String SELECTION =
"("+ContactsContract.Contacts.HAS_PHONE_NUMBER +"='1') OR " + RawContacts.ACCOUNT_TYPE + "='" + Constants.ACCOUNT_TYPE + "'";
现在,问题是,我在查询中使用的 ContactsContract.Contacts.CONTENT_URI
中不存在 RawContacts.ACCOUNT_TYPE
。我猜我需要加入另一张桌子,但不知道该怎么做。
有人可以帮我吗?
I have a problem in querying phonebook contacts. What I need to do is get a list of contacts that have both phone and email entered or are of a specific type.
Basically like this:
public static final String SELECTION =
"("+ContactsContract.Contacts.HAS_PHONE_NUMBER +"='1') OR " + RawContacts.ACCOUNT_TYPE + "='" + Constants.ACCOUNT_TYPE + "'";
Now, the problem is, that RawContacts.ACCOUNT_TYPE
does not exist in the ContactsContract.Contacts.CONTENT_URI
, which I use with my query. I'm guessing I'd need to join another table, but have no idea how to do so.
Can anyone help me here, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
读取原始联系人及其关联的所有数据的最佳方法是使用
ContactsContract.RawContacts.Entity
目录。如果原始联系人具有数据行,则实体游标将为每个数据行包含一行。如果原始联系人没有数据行,则游标仍将包含一行包含原始联系人级别信息。您必须根据 mimeType 过滤结果。
例如,如果 mimeType 为
Phone.CONTENT_ITEM_TYPE
,则列DATA1
存储电话号码,但如果数据类型为是Email.CONTENT_ITEM_TYPE
,则DATA1
存储电子邮件地址。这样您就不必使用
HAS_PHONE_NUMBER
,因为您将直接迭代项目。The best way to read a raw contact along with all the data associated with it is by using the
ContactsContract.RawContacts.Entity
directory. If the raw contact has data rows, the Entity cursor will contain a row for each data row. If the raw contact has no data rows, the cursor will still contain one row with the raw contact-level information.You will have to filter the result based on the mimeType
For example, if the mimeType is
Phone.CONTENT_ITEM_TYPE
, then the columnDATA1
stores the phone number, but if the data kind isEmail.CONTENT_ITEM_TYPE
, thenDATA1
stores the email address.This way you won't have to use
HAS_PHONE_NUMBER
as you will directly iterate trough the items.也许您应该使用
Email.CONTENT_URI
,因为它包含"vnd.android.cursor.item/email_v2"
MIME 类型的所有数据记录,以及关联的原始联系人和汇总联系人数据。Maybe you should use
Email.CONTENT_URI
as it contains all data records of the"vnd.android.cursor.item/email_v2"
MIME type, combined with the associated raw contact and aggregate contact data.