开发者

Honeycomb ContactsContract.Directory - Display photo in User Details

开发者 https://www.devze.com 2023-04-05 16:10 出处:网络
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

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 contac开发者_如何学Got 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);
    }


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.

0

精彩评论

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

关注公众号