Android - Storage Access Framework - Uri into local file

与世无争的帅哥 提交于 2019-12-12 04:17:22

问题


I am using Storage Access Framework(SAF) in my app. In order to scan a file(photo or document) i need send a local file path trough an API. I've managed to setup the SAF correctly, and now when a user chooses a file and i am getting a Uri as it supposed to be.

As it seems the Uri is a key for the cloud and not a local file.

The Uri value looks like that:

content://com.android.providers.media.documents/document/image:11862 

How can i convert this Uri into a local file? Should i download the file from the cloud? How can i do it?


回答1:


As it seems the Uri is a key for the cloud and not a local file.

The Uri is an opaque reference to a piece of content. You have no way of knowing where the data is, nor should you care.

How can i convert this Uri into a local file?

Ideally, you don't. Ideally, you "scan a file(photo or document)" using some library that supports an InputStream. In that case, you use ContentResolver and openInputStream() to get the stream to pass to the library.

If your library does not support InputStream as a data source, you will need to use openInputStream() yourself, using Java I/O to make a copy of the content as a file in the filesystem, for you to pass to the library.



来源:https://stackoverflow.com/questions/34790326/android-storage-access-framework-uri-into-local-file

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