从开放的Andr​​oid的棒棒糖获得路径名 [英] get Path name from Uri Android Lollipop

查看:116
本文介绍了从开放的Andr​​oid的棒棒糖获得路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

棒棒糖版本。

我用这个 code 来确定开放的文件路径。工作正常,但如果让我选择的文件从下载的应用程序 - getRealPathFromURI_API19 功能不为我工作。整个ID为这种情况下等于/文件/ 4例如,我的应用程序是崩溃了。

好吧,我做了一些改变,这个功能ID的URI/文件/ 4现在等于4,但函数返回null。

是不是从任何应用程序选取图像可能获取文件的路径? 我需要的文件路径ExifInterface。

解决方案
  

做工精细

只有对你尽力了,为一个文件源的一些设备(MediaStore <$ C C $>)你的努力程度。

  

是否有可能获取文件路径选取图像从任何应用程序?

没有。 A 乌里不是文件 。没有为不要求任何乌里兑换成文件的路径,因为乌里不得重新present一个文件,更何况你的应用程序有权限访问的文件。对你来说,一个乌里是一个不透明的地址被其他应用程序内容拥有的,就像一个URL是一个不透明的地址由Web服务器内容的拥有。而且,正如你不能神奇地将URL转换为一个文件路径,您可以使用,你不能神奇地转换乌里成可以使用的文件的路径。

  

我需要的文件路径ExifInterface。

在现实中,你需要阅读,或可能写,用 URI关联EXIF头您认为指向包含这些头的图像。虽然 ExifInterface 可以让你做到这一点,它是专为应用程序与他们自己的形象,而不是图像来自第三方的应用程序工作。

您的选择是:

  • 使用 ContentResolver的 openInputStream()乌里,使图像的本地副本后,您可以使用 ExifInterface

  • 使用一些其他的EXIF code,它提供了更多的灵活性。例如,<一个href="https://android.googlesource.com/platform/packages/apps/Mms/+/master/src/com/android/mms/exif/ExifReader.java"相对=nofollow>从AOSP彩信应用可以读取EXIF头的EXIF类的的InputStream

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

这篇关于从开放的Andr​​oid的棒棒糖获得路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆