开发者

Using ContactsContract.Contacts.Data

开发者 https://www.devze.com 2023-02-25 06:31 出处:网络
From the Android documentation, I gather that开发者_StackOverflow I can append the ContactsContract.Contacts.Data.CONTENT_DIRECTORY string to ContactsContract.Contacts.CONTENT_URI and be able to acces

From the Android documentation, I gather that开发者_StackOverflow 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消