Honeycomb ContactsContract.Directory - 在用户详细信息中显示照片
我已经设法让 ContactsContact.Directory 大部分工作(http://stackoverflow.com/questions/7436969/contactscontract-directory-how-do-i-return-a-photo),并加载照片进行搜索结果缩略图。我还可以从 LOOKUP URI 查看联系方式。但我无法在联系方式中调出用户照片。
我的数据并不驻留在数据库中,而是全部来自 HTTPS REST 查询。
为了解决图像不是本地的问题,我创建了第二个内容提供程序,它仅采用 URI、解析参数 (url) 并通过覆盖 openFile (http:// stackoverflow.com/questions/3883211/how-to-store-large-blobs-in-an-android-content-provider)。这样,当我将 uri 作为 PHOTO_THUMBNAIL_URI 传回时,
效果很好,并且可以在联系人的结果部分中快速显示图像。我现在的问题是无法在联系人详细信息屏幕中加载照片。
我知道它正在对我的目录提供程序进行第二次查询以进行查找,我正在解析所有字段,尽管它只要求 PHOTO_URI,而不是 PHOTO_THUMBNAIL_URI,这没什么大不了的,因为我将相同的 URI 传递给我的内容提供程序。但这一次它似乎无法正常工作,因为它甚至没有尝试访问我的照片提供商。
然后我决定尝试在本地解析&下载照片数据并将 Byte[] 数据作为 PHOTO (Data15) 包含在查找响应中,但这也不起作用。
此时任何帮助将不胜感激。
static void addPhotoRow(MatrixCursor cursor, UdsProjection udsProjection, long contactId,
String lookupKey, String accountName, String displayName, String photoUri) {
UdsContactRow r = new UdsContactRow(
udsProjection, contactId, lookupKey, accountName, displayName);
r.put(Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
r.put(Photo.PHOTO_ID, photoUri);
//r.put(Photo.PHOTO, getPhotoBytes(photoUri));
cursor.addRow(r.getRow());
Log.e("TAG","Adding photo row " + photoUri);
}
I have managed to get a ContactsContact.Directory working for the most part (http://stackoverflow.com/questions/7436969/contactscontract-directory-how-do-i-return-a-photo), and loading photos for the search result thumbnails. I can also view the contact details from the LOOKUP URI. But I am not able to pull up the user photo in the contact details.
My data does not reside in a database, but its all from a HTTPS REST Query.
To get around the image not being local, I created a second content provider which simply takes a URI, parses a parameter (url) and downloads an image (if not already cached on the sdcard) by way of overriding openFile (http://stackoverflow.com/questions/3883211/how-to-store-large-blobs-in-an-android-content-provider). That way when I pass the uri back as PHOTO_THUMBNAIL_URI
This works great and displays the images quite quickly in the results section of contacts. My issue is now that I can't load the photo in the contact details screen.
I understand that it is making a second query to my Directory Provider for LOOKUP, I am parsing all the fields, although it only asks for PHOTO_URI, not PHOTO_THUMBNAIL_URI, not a big deal as I am passing the same URI to my content provider.. But this time it does not seem to work correctly, as it does not even attempt to hit my photo provider.
I then decided to try and just locally parse & download the photo data and include the Byte[] data as PHOTO (Data15) in the Lookup Response, but that does not work either.
Any help would be greatly appreciated at this point.
static void addPhotoRow(MatrixCursor cursor, UdsProjection udsProjection, long contactId,
String lookupKey, String accountName, String displayName, String photoUri) {
UdsContactRow r = new UdsContactRow(
udsProjection, contactId, lookupKey, accountName, displayName);
r.put(Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
r.put(Photo.PHOTO_ID, photoUri);
//r.put(Photo.PHOTO, getPhotoBytes(photoUri));
cursor.addRow(r.getRow());
Log.e("TAG","Adding photo row " + photoUri);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我可以对结果进行一些说明。显然,将项目添加到返回的光标的顺序确实很重要。我将光标中的照片哑剧类型行移到任何详细信息(例如电话号码)之前,然后它开始工作。希望这能帮助其他人在一个下午的时间里摆脱困境。
So I can shed some light on the results. Apparently the order in which you add your items to the cursor you return really matters. I moved the Photo mime type row in my cursor ahead of any of the details (such as phone number) and then it started working.. Hopefully this will help someone else from pulling their hair out for an afternoon.