Android 从相对 uri 打开 InputStream 到 ACTION_OPEN_DOCUMENT? [英] Android open InputStream from relative uri to ACTION_OPEN_DOCUMENT?

本文介绍了Android 从相对 uri 打开 InputStream 到 ACTION_OPEN_DOCUMENT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 android 4.4(api 级别 19)中打开与 json 配置文件相关的多个文件,我用过

I'am trying to open multiple files relative to a json configuration file in android 4.4 (api level 19), I used

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType({mime});
this.startActivityForResult(intent, {code});

让用户找到配置文件,并从那里打开我知道配置文件路径的多个文件.

to let the user find te configuration file, and from there open multiple files that I know the path from the config file.

但是我明白

Caused by: java.lang.SecurityException: 
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider
uri content://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/{relative file}
requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs

我不想使用用户界面打开其他文件,所以我尝试添加以下权限但没有得到任何结果

I dont want to use user interfaces to open the other files, so I tried adding the following permissions without getting any results

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS "/>

我宁愿将文件分开,而不是放在 blob 或 zip 文件中

I would rather have the files separated and not in a blob or a zip file

推荐答案

ACTION_OPEN_DOCUMENT 只允许您访问文件(或文件,如果您使用 EXTRA_ALLOW_MULTIPLE) 用户选择.

ACTION_OPEN_DOCUMENT only gives you access to exactly the file (or files, if you use EXTRA_ALLOW_MULTIPLE) that the user selects.

您可以使用 ACTION_OPEN_DOCUMENT_TREE 来允许用户选择一个文件夹 - 然后您将可以访问该文件夹(及其子文件夹)中的所有文件.

You can use ACTION_OPEN_DOCUMENT_TREE to allow the user to select a folder - you'll then get access to all files in that folder (and their subfolders).

这篇关于Android 从相对 uri 打开 InputStream 到 ACTION_OPEN_DOCUMENT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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