我正在尝试显示联系信息,而对于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中的managedQuery已被更改(我相信原来的问题,我将其引用到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)
答案 0 :(得分:1)
我不知道Contacts.CONTENT_LOOKUP_URI
的作用,但我使用RawContacts.CONTENT_URI
。
因此,尝试Uri contacts = ContactsContract.RawContacts.CONTENT_URI
或Uri contacts = ContactsContract.Contacts.CONTENT_URI
也应该有用。
如果你没有指定selectionArgs
(第三个参数),请保留selection
(第四个参数),因为只有在给出selection
时它们才会生成。 / p>