开发者

ContactsContract.Directory - How do I return a Photo?

开发者 https://www.devze.com 2023-04-05 17:56 出处:网络
I am trying to figure out why I can\'t seem to pass a photo Uri (Uri.parse(http://url/image.png)) to the contacts app via ContactsContract.Directory

I am trying to figure out why I can't seem to pass a photo Uri (Uri.parse(http://url/image.png)) to the contacts app via ContactsContract.Directory

I have a web service which allows searching of an address book. One of the returned fields is a url of the contact which resides on a webserver which I have verified is accessible from my Honeycomb Tablet.

My ContactsContract.Directory seems to be working 开发者_如何学编程flawlessly returning results, but when I pass back as part of the FILTER query Contacts.PHOTO_THUMBNAIL_URI w/ the Uri.parse(http://url/image.png) the search results still return as expected, but I still only see the temporary template.

The uri for the directory query has an option for photo supported.

if (column.equals(Directory.PHOTO_SUPPORT)) {
                    row[i] = Directory.PHOTO_SUPPORT_FULL;
                }

I have tried all combinations of Directory.PHOTO_SUPPORT* and none seem to make a difference.

My only thought is that the contacts app does not support downloading photos from a URL. So I also tried

    File myFile  = new File("/sdcard/testuser.jpg");
row[photoUri] = Uri.fromFile(myFile);

And I verified that testuser.jpg was on the sdcard. This worked fine. However due to the way the directory search is done I would like to load it on the fly, and not cache (for the time being) to the sdcard.

Any help would be appreciated.


I think I have found the answer.. Looks like the exception was being logged in Verbose (had my logcat set at Debug). Anyway, was pretty sure about this, but looks like there is no Provider for http uri. Off to create a content provider, just not sure how I will return an image from a content provider, but will figure it out. Any hints/tips would be appreciated and given answer credit.

09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691): java.io.FileNotFoundException: No content provider: http://domain/testimage.jpg
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:595)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:527)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at android.content.ContentResolver.openInputStream(ContentResolver.java:362)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at com.android.contacts.ContactPhotoManagerImpl$LoaderThread.loadRemotePhotos(ContactPhotoManager.java:722)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at com.android.contacts.ContactPhotoManagerImpl$LoaderThread.loadPhotosInBackground(ContactPhotoManager.java:652)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at com.android.contacts.ContactPhotoManagerImpl$LoaderThread.handleMessage(ContactPhotoManager.java:563)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at android.os.Handler.dispatchMessage(Handler.java:95)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at android.os.Looper.loop(Looper.java:132)
09-16 10:20:25.550: VERBOSE/ContactPhotoManager(11691):     at android.os.HandlerThread.run(HandlerThread.java:60)
0

精彩评论

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

关注公众号