getRealPathFromURI() not working with ICS & Picasa based images

一笑奈何 提交于 2019-12-12 11:10:16

问题


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)

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

and running getRealPathFromURI(theURI) returns 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? 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.

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

  1. The user selected a local image file

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

  3. 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/


回答1:


That's what I found out on device running 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. 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);


来源:https://stackoverflow.com/questions/11150108/getrealpathfromuri-not-working-with-ics-picasa-based-images

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