getRealPathFromURI()不与ICS和放大器的工作;基于图像的Picasa放大器、不与、图像、工作

2023-09-08 00:07:15 作者:温柔喂了狗

我试图让以将其上传到服务器的图像的本地路径。当使用pre ICS将通过获取Android设备中的标准路径getRealPathFromURI(theURI)

I'm trying to get the local path of a image in order to upload it to a server. When using pre ICS it would get a standard path within the android device via getRealPathFromURI(theURI)

然而,随着ICS URI将包含 uriString中,就像这样:内容://com.google.android.gallery3d.provider/picasa/项目/ 12312312312312

However with ICS URI will contain a uriString as something like : content://com.google.android.gallery3d.provider/picasa/item/12312312312312.

和运行 getRealPathFromURI(theURI)收益

我现在需要提取通过API上述 uriString中并手动下载图像(如果我发现,它的一个Picasa图片库的图像),而不是一个本地存储?还是我完全失去了一些东西?

Do I now need to extract the above uriString and manually download the image via the API (if i detect that its a Picasa gallery image) rather than one locally stored? or am I completely missing something?

感谢您的任何建议。

编辑:

好像我是在错误的问题...

seems i was searching on the wrong question...

发现下面的链接...这是pretty很多我所期待的我需要做的问题。 pretty讨厌谷歌/ Android的没有更优雅的处理这个问题。

found the problem in the below link... which is pretty much what I expected I'd need to do. Pretty annoying google/android didn't handle this more elegantly.

要妥善处理,你需要处理三个场景图库获取图像:

To properly handle fetching an image from the Gallery you need to handle three scenarios:

选择本地图片文件,用户

The user selected a local image file

选择Picasa图片和设备上的用户正在运行之前的3.0版本的Andr​​oid

The user selected a Picasa image and the device is running Android version prior to 3.0

选择Picasa图片的用户,并该设备运行的是Android 3.0及更高

The user selected a Picasa image and the device is running Android version 3.0 and higher

http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/

推荐答案

这是我发现的设备运行Android 4.0 +

That's what I found out on device running Android 4.0+.

你给作为例子的ICS URI是URI与内容://方案,所以应该有负责该ContentProvider的。因此,有什么用的招数getRealPathFromURI()使用的?就让ContentResolver的为你做这项工作:

The ICS URI you gave as an example is an URI with content:// scheme, so there should be a ContentProvider responsible for that. Hence, what is the use of that tricks getRealPathFromURI() uses? Just let ContentResolver do this work for you:

InputStream inStream = getContentResolver().openInputStream(theUri);
Bitmap bitmap = BitmapFactory.decodeStream(is);