ContactsContract.Directory - How do I return a Photo?

江枫思渺然 提交于 2019-12-12 04:37:44

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/7436969/contactscontract-directory-how-do-i-return-a-photo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!