安卓; 2.2 中的manageQuery 是如何工作的?

发布于 2024-09-16 07:24:58 字数 2146 浏览 4 评论 0原文

我正在尝试显示联系信息,并且从 stackOverflow 上的另一个问题中我得到了以下代码片段

String[] projection = new String[] {
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Email.DISPLAY_NAME
     };

    Uri contacts =  ContactsContract.Contacts.CONTENT_LOOKUP_URI;
    //id of the Contact to return.
    long id = 3;

    //Make the query. 
    Cursor managedCursor = managedQuery(contacts,
                                        projection, // Which columns to return 
                                        null,       // Which rows to return (all rows)
                // Selection arguments (with a given ID)
                                        ContactsContract.Contacts._ID = "id", 
                // Put the results in ascending order by name
                                        ContactsContract.Contacts.DISPLAY_NAME + " ASC");

似乎托管查询已在 2.2 中更改(我相信我得到此信息的原始问题引用了 2.0)

发生了什么变化在2.2中?我找不到显示联系人电子邮件、电话号码等的方法

编辑:这是我可以从 android 调试日志中找到的所有内容

08-24 20:49:51.893: ERROR/DatabaseUtils(519): Writing exception to parcel
08-24 20:49:51.893: ERROR/DatabaseUtils(519): java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/lookup, calling user: com.example.android.contactmanager, calling package:com.example.android.contactmanager
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at com.android.providers.contacts.LegacyApiSupport.query(LegacyApiSupport.java:1911)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:4697)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:150)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at android.os.Binder.execTransact(Binder.java:288)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at dalvik.system.NativeStart.run(Native Method)

I'm trying to display contact information, and from another question on stackOverflow I've got the following snippet

String[] projection = new String[] {
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Email.DISPLAY_NAME
     };

    Uri contacts =  ContactsContract.Contacts.CONTENT_LOOKUP_URI;
    //id of the Contact to return.
    long id = 3;

    //Make the query. 
    Cursor managedCursor = managedQuery(contacts,
                                        projection, // Which columns to return 
                                        null,       // Which rows to return (all rows)
                // Selection arguments (with a given ID)
                                        ContactsContract.Contacts._ID = "id", 
                // Put the results in ascending order by name
                                        ContactsContract.Contacts.DISPLAY_NAME + " ASC");

It seems that the managedQuery has been changed in 2.2 (I belive the original question where I got this was referenced to 2.0)

What has changed in 2.2? I can't find a way of displaying emails, phone numbers etc for a contact

EDIT : This is all I can find from the android debugging logs

08-24 20:49:51.893: ERROR/DatabaseUtils(519): Writing exception to parcel
08-24 20:49:51.893: ERROR/DatabaseUtils(519): java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/lookup, calling user: com.example.android.contactmanager, calling package:com.example.android.contactmanager
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at com.android.providers.contacts.LegacyApiSupport.query(LegacyApiSupport.java:1911)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:4697)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:150)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at android.os.Binder.execTransact(Binder.java:288)
08-24 20:49:51.893: ERROR/DatabaseUtils(519):     at dalvik.system.NativeStart.run(Native Method)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So尛奶瓶 2024-09-23 07:24:58

我不知道 Contacts.CONTENT_LOOKUP_URI 的用途,但我使用 RawContacts.CONTENT_URI

因此,尝试 Uricontacts = ContactsContract.RawContacts.CONTENT_URIUricontacts = ContactsContract.Contacts.CONTENT_URI 也应该可以。

如果您没有指定选择(第三个参数),请保留selectionArgs(第四个参数),因为它们仅在选择时才有意义。代码>给出。

I don't know what the Contacts.CONTENT_LOOKUP_URI does, but I use the RawContacts.CONTENT_URI.

So try Uri contacts = ContactsContract.RawContacts.CONTENT_URI or Uri contacts = ContactsContract.Contacts.CONTENT_URI should also work.

And leave the selectionArgs (4th-argument) if you didn't specify a selection (3rd-argument), because they only make sence if a selection is given.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文