[英]getRealPathFromURI() not working with ICS & Picasa based images
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)
当使用pre ICS时,它将通过
getRealPathFromURI(theURI)
在Android设备中获得标准路径
However with ICS URI will contain a uriString
as something like : content://com.google.android.gallery3d.provider/picasa/item/12312312312312
. 但是,ICS URI将包含一个
uriString
,如: content://com.google.android.gallery3d.provider/picasa/item/12312312312312
。
and running getRealPathFromURI(theURI)
returns null
并运行
getRealPathFromURI(theURI)
返回null
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? 我现在需要提取上面的
uriString
并通过API手动下载图像(如果我检测到它是Picasa图库图像)而不是本地存储的图像吗? or am I completely missing something? 还是我完全错过了什么?
thanks for any advice 谢谢你的建议
EDIT: 编辑:
seems i was searching on the wrong question... 好像我在寻找错误的问题......
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.
相当恼人的谷歌/ android没有更优雅地处理这个。
To properly handle fetching an image from the Gallery you need to handle three scenarios: 要正确处理从图库中提取图像,您需要处理三种情况:
The user selected a local image file 用户选择了本地图像文件
The user selected a Picasa image and the device is running Android version prior to 3.0 用户选择了Picasa图像,设备正在运行3.0之前的Android版本
The user selected a Picasa image and the device is running Android version 3.0 and higher 用户选择了Picasa图片,设备正在运行Android 3.0及更高版本
http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/ http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/
That's what I found out on device running Android 4.0+. 这就是我在运行Android 4.0+的设备上发现的。
The ICS URI you gave as an example is an URI with content:// scheme, so there should be a ContentProvider responsible for that. 您提供的ICS URI是一个带有content:// scheme的URI,因此应该有一个ContentProvider负责。 Hence, what is the use of that tricks getRealPathFromURI() uses?
因此,getRealPathFromURI()使用的技巧有什么用? Just let ContentResolver do this work for you:
让ContentResolver为您完成这项工作:
InputStream inStream = getContentResolver().openInputStream(theUri);
Bitmap bitmap = BitmapFactory.decodeStream(is);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.