get Path name from Uri Android Lollipop

前端 未结 1 1603
一生所求
一生所求 2021-01-26 20:23

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 fu

相关标签:
1条回答
  • 2021-01-26 21:07

    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

    0 讨论(0)
提交回复
热议问题