简体   繁体   English

从Gallery中检索非缓存的Picasa图像。 3.0和4.0

[英]Retrieve a non cached Picasa image from Gallery. 3.0 and 4.0

My app is calling the gallery with an intent that looks like this: 我的应用程序调用库的意图如下:

Intent intent = new Intent(Intent.ACTION_PICK,
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, SELECT_IMAGE_FROM_GALLERY);

In versions < 3.0 there's no problem. 在<3.0版本中没有问题。

With 3.0 and greater versions, when you get a local image, the intent in the onActivityResult method contains an Uri like... 对于3.0及更高版本,当您获得本地图像时,onActivityResult方法中的意图包含类似于Uri的...

content://media/external/images/media/XXX

but when you select a picasa image the uri is something like... 但是当你选择一个picasa图像时,uri就像......

content://com.google.android.gallery3d.provider/picasa/item/XXXXXXXXXXXXXXXXXXXXX

I read many about that problem and I tried many workarounds. 我读了很多关于这个问题的文章,我尝试了很多解决方法。

At the moment, I can obtain just cached images using: 目前,我可以使用以下方法获取缓存的图像:

getContentprovider().openInputStream(uri)

The problem is that, when the image is not cached, the openInputStream(uri) method, throws a FileNotFoundException , and i can't get the image :_( 问题是,当图像没有被缓存时, openInputStream(uri)方法抛出一个FileNotFoundException ,我无法获取图像:_(

Anyone knows how to get the file or the url to download the file or something to get the image?? 任何人都知道如何获取文件或网址下载文件或东西来获取图像?

Thanks!! 谢谢!!

The correct solution is to use ACTION_GET_CONTENT . 正确的解决方案是使用ACTION_GET_CONTENT Its name may not sound as intuitive as ACTION_PICK but it's the one you should use for what you are trying to do. 它的名字可能听起来不像ACTION_PICK那么直观,但它应该用于你想要做的事情。

The reason behind using ACTION_GET_CONTENT for picking an image in your gallery instead of using ACTION_PICK and pointing to the ImageStore's URI provider is that ACTION_GET_CONTENT is well supported , whereas ACTION_PICK is not . 使用ACTION_GET_CONTENT选择图库中的图像而不是使用ACTION_PICK并指向ACTION_GET_CONTENT的URI提供程序的原因是ACTION_GET_CONTENT得到了很好的支持 ,而ACTION_PICK没有 It's been mentioned a couple of times by Android Framework engineers. Android Framework工程师已经多次提到它。

I learned it the hard way. 我很难学到它。 Before finding out about this I had to deal with various inconsistencies. 在发现这一点之前,我不得不处理各种不一致问题。


A note related to this 与此相关的说明

You should always use openInputStream to obtain the file through a ContentResolver with the URI received instead of trying to obtain the real path in which the file is being stored. 您应始终使用openInputStream通过带有URIContentResolver获取文件,而不是尝试获取存储文件的实际路径。 It may well be the case that the ContentProvider implementation is backed by a cloud service (this is the case with Picasa) or the implementation details change over time. 很可能是ContentProvider实现由云服务支持(Picasa就是这种情况),或者实现细节随时间而变化。

Android's content providers let you abstract how the data is being accessed. Android的内容提供商允许您抽象数据的访问方式。 Trying to find out where the file is located is a common error I see. 试图找出文件所在的位置是我看到的常见错误。 Usually what is suggested is to find the location by querying the DATA column of the given URI . 通常建议的是通过查询给定URIDATA列来查找位置。 Depending on the ContentProvider used it may return different things and even change over time with new versions. 根据使用的ContentProvider它可能返回不同的东西,甚至随着时间的推移随新版本而变化。

By using openInputStream you don't have to care about where the file is, you just receive the stream of bytes and do what you wish with it. 通过使用openInputStream您不必关心文件的位置,您只需接收字节流并按照您的意愿执行操作。 This way you won't have problems supporting content providers from other apps like Google Drive, Dropbox, etc that provide a similar picker interface to select an image. 这样,您就不会遇到支持来自Google Drive,Dropbox等其他应用程序的内容提供商的问题,这些应用程序提供类似的选择器界面来选择图像。

I know OP is using openInputStream , but other answers are suggesting otherwise and it's something I see too frequently. 我知道OP正在使用openInputStream ,但是其他的答案是建议的,这是我经常看到的。

Another way to get the bitstream for the picture is thru the picasa api.... 获取图片比特流的另一种方法是通过picasa api ....

applying some mapping to content provider uri ... 将一些映射应用于内容提供商uri ...

content://com.google.android.gallery3d.provider/picasa/item/5703943700733980450 内容://com.google.android.gallery3d.provider/picasa/item/5703943700733980450

one can map it to a picasa api like the following: 可以将它映射到picasa api,如下所示:

item=>photoid name?? item => photoid name ?? albumid?? ALBUMID?

picasaweb.google.com/data/entry/api/user/$NAME/albumid/nnnn/photoid/nnnn picasaweb.google.com/data/entry/api/user/$NAME/albumid/nnnn/photoid/nnnn

Above is an api request for photo entry - see picasa docs for details. 以上是照片录入的api请求 - 有关详细信息,请参阅picasa文档。

API requires API要求

Name albumID photoID 名称albumID photoID

Name i think u can get from the account on the phone. 姓名我想你可以通过电话从帐户中获取。 AlbumID is tricky because the /item/ node value in the content provider is not a GUID that can use a relationship to infer the album that its in. I don't think.. AFAIK in picasa , you need the user,album,photo tuple to get a reference to a photo entry and the photo entry has the URL for the large photo in the API element: AlbumID很棘手,因为内容提供商中的/ item / node值不是可以使用关系来推断它所在的专辑的GUID。我不认为..在picasa中的AFAIK,你需要用户,专辑,照片元组获取对照片条目的引用,照片条目具有API元素中大照片的URL:

"media$group":{ "media$content":[ {"url": “media $ group”:{“media $ content”:[{“url”:

You can take the textvalue of the url attribute and request it using http(s) if the visibility of the album is public. 如果专辑的可见性是公开的,您可以使用url属性的textvalue并使用http(s)请求它。 The response is the binary stream of the JPG. 响应是JPG的二进制流。

php picasa api show large image php picasa api显示大图像

see the accepted answer in the above link for more details on getting the image that you want from the picasa api. 有关从picasa api获取所需图像的更多详细信息,请参阅上述链接中的已接受答案。

Using one of my own content URI's in an example... 在示例中使用我自己的内容URI之一...

content://com.google.android.gallery3d.provider/picasa/item/5703943700733980450 内容://com.google.android.gallery3d.provider/picasa/item/5703943700733980450

is not available in cache so how to get the image? 在缓存中不可用,那么如何获取图像?

well the name on the account is 'rowntreerob' and i know that photoid 5703943700733980450 belongs to albumid 5703943611411433905. 好吧,帐户上的名字是'rowntreerob',我知道photoid 5703943700733980450属于albumid 5703943611411433905。

So, i make an api request for the entry 所以,我为这个条目提出了api请求

https://picasaweb.google.com//data/entry/api/user/rowntreerob/albumid/5682316071017984417/photoid/5682316083381958690?fields=media%3Agroup%2Fmedia%3Athumbnail%5B%40url%5D%2Cmedia%3Agroup%2Fmedia%3Acontent%5B%40url%5D&alt=json https://picasaweb.google.com//data/entry/api/user/rowntreerob/albumid/5682316071017984417/photoid/5682316083381958690?fields=media%3Agroup%2Fmedia%3Athumbnail%5B%40url%5D%2Cmedia%3Agroup%2Fmedia %3Acontent%5B%40url%5D&ALT = JSON

and check the response for the text value of 并检查文本值的响应

"media$group":{ "media$content":[ {"url": “media $ group”:{“media $ content”:[{“url”:

value= https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG value = https://lh3.googleusercontent.com/-_FFMNGPU1TQ/TtukXyN4eCI/AAAAAAAACso/EzPmut2iKVQ/DSC01612.JPG

I make a photo image request using the value above and i have the image. 我使用上面的值制作照片图像请求,我有图像。


The Gallery 3D app also has the code you could fork because whereever it detects a 'touch' on one of the list of thumbnails, it delegates to the contentProvider interface to 'get' the BMP. Gallery 3D应用程序还具有您可以分叉的代码,因为无论它在缩略图列表中检测到“触摸”,它都会委托给contentProvider界面以“获取”BMP。 I believe that this interface encapsulates all the gory implementation nits mentioned above. 我相信这个接口封装了上面提到的所有gory实现nits。 By asking the ContentProvider to produce the BMP, the developer doesnt have to worry about the flavor of implementation?? 通过要求ContentProvider生成BMP,开发人员不必担心实现的风格? On the thumbtouch, Gallery3d may just ask the provider to return the BMP and its the provider instance that is responsible for resolving the various states of the cache and whether network calls will be required to return the BMP. 在缩略图上,Gallery3d可能只是要求提供者返回BMP及其负责解析缓存各种状态的提供者实例,以及是否需要网络调用来返回BMP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM