Lollipop version.
I used this code to determine file path from Uri. Works fine, but if I choose file from a Downloaded app - getRealPathFromURI_API19 function does not work for me. whole Id for this case equals /document/4 for example, and my app was crashed.
Ok, I made some changes for this function and "id" for Uri "/document/4" now equals 4, but function returns null.
Is it possible get file path for choosed image from any app? I need file path for ExifInterface.
Only for the few devices that you tried, for the one file source (
MediaStore
) that you tried.No. A
Uri
is not aFile
. There is no requirement for anyUri
to be convertible into file path, as theUri
may not represent a file, let alone a file that your app has the rights to access. To you, aUri
is an opaque address to content owned by another app, much as a URL is an opaque address to content owned by a Web server. And, just as you cannot magically convert a URL into a file path that you can use, you cannot magically convert aUri
into a file path that you can use.In reality, you need to read, or possibly write, EXIF headers associated with a
Uri
that you believe points to an image that contains those headers. WhileExifInterface
lets you do that, it is designed for apps to work with their own images, not images from third-party apps.Your choices are:
Use
ContentResolver
andopenInputStream()
on theUri
, and make a local copy of the image, after which you can useExifInterface
Use some other EXIF code that offers more flexibility. For example, the EXIF classes from the AOSP Mms app can read EXIF headers from an
InputStream