使用 ContactsContract.Contacts.Data
从Android文档中,我了解到我可以将ContactsContract.Contacts.Data.CONTENT_DIRECTORY字符串附加到ContactsContract.Contacts.CONTENT_URI,并且能够访问联系人的字段和数据的字段。不幸的是,我在这段代码中遇到了异常。
Cursor cursor = context.getContentResolver().query(
Uri.withAppendedPath(Contacts.CONTENT_URI, Contacts.Data.CONTENT_DIRECTORY),
null, null, null, null);
我得到的异常是:
java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/data, calling user: ...
我做错了什么?注意:我使用的是Android 2.1
From the Android documentation, I gather that I can append the ContactsContract.Contacts.Data.CONTENT_DIRECTORY string to ContactsContract.Contacts.CONTENT_URI and be able to access both Contact's fields and Data's fields. Unfortunately I am getting an exception with this code
Cursor cursor = context.getContentResolver().query(
Uri.withAppendedPath(Contacts.CONTENT_URI, Contacts.Data.CONTENT_DIRECTORY),
null, null, null, null);
The exception I get is:
java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/data, calling user: ...
What am I doing wrong? Note: I am using Android 2.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档没有明确说明的是,ContactsContract.Contacts.Data 用于访问单个联系人的连接联系人和数据表。它期望看到联系人 ID 或查找键。我到处都找过了,但目前还没有办法加入联系人和数据表。希望他们能够增加对此的支持。看起来唯一公开的用于连接全表的 API 是 RawContactsEntity (在这方面与 RawContacts.Entity 不同)
所以据我所知,类比是:
RawContacts.Entity 是 Contacts.Data
因为 RawContactsEntity 毫无意义。
Android 确实需要添加对全表连接的支持,而不仅仅是 RawContacts
Something that the documentation doesn't make clear is that ContactsContract.Contacts.Data is for accessing a joined Contacts and Data table for a single contact. It expects to see a contact id or a lookup key. I've looked everywhere, but there is currently no way to join Contacts and Data tables. Hopefully they will add support for this. It looks like the only exposed API for joining full tables is RawContactsEntity (which is different than RawContacts.Entity in this respect)
So AFAIK the analogy is:
RawContacts.Entity is to Contacts.Data
as RawContactsEntity is to nothing.
Android really needs to add support for full table joins on more than just RawContacts