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.
Works fine
Only for the few devices that you tried, for the one file source (MediaStore
) that you tried.
Is it possible get file path for choosed image from any app?
No. A Uri
is not a File
. There is no requirement for any Uri
to be convertible into file path, as the Uri
may not represent a file, let alone a file that your app has the rights to access. To you, a Uri
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 a Uri
into a file path that you can use.
I need file path for ExifInterface.
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. While ExifInterface
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
and openInputStream()
on the Uri
, and make a local copy of the image, after which you can use ExifInterface
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