安卓; 2.2 中的manageQuery 是如何工作的?
我正在尝试显示联系信息,并且从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道
Contacts.CONTENT_LOOKUP_URI
的用途,但我使用RawContacts.CONTENT_URI
。因此,尝试
Uricontacts = ContactsContract.RawContacts.CONTENT_URI
或Uricontacts = ContactsContract.Contacts.CONTENT_URI
也应该可以。如果您没有指定
选择
(第三个参数),请保留selectionArgs
(第四个参数),因为它们仅在选择
时才有意义。代码>给出。I don't know what the
Contacts.CONTENT_LOOKUP_URI
does, but I use theRawContacts.CONTENT_URI
.So try
Uri contacts = ContactsContract.RawContacts.CONTENT_URI
orUri contacts = ContactsContract.Contacts.CONTENT_URI
should also work.And leave the
selectionArgs
(4th-argument) if you didn't specify aselection
(3rd-argument), because they only make sence if aselection
is given.