问题标签 [documentfile]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1264 浏览

android - 检查 DocumentFile 是否存在

我使用 DocumentFile 检查文件元数据和存在。这是这样实例化的:

该文件的 uri 以前有效,直到我故意在文件系统中手动删除该文件以查看应用程序将如何反应。现在这个堆栈跟踪出现在应用程序中:

不会使应用程序崩溃,它只会在我每次尝试使用 DocumentFile 时生成此堆栈跟踪。所以在最坏的情况下,这只是 logcat 中的一个刺激物。

我希望FileNotFoundException使用.exists(). 当我检查它是否存在以避免使用不存在的文件时。

在这种情况下是否推荐使用不同的功能?

0 投票
0 回答
211 浏览

android - Android - 使用 DocumentFile 类的文件操作是否需要提醒 MediaScanner?

我试图遵循源代码并保留这篇文章,但我有点迷路了..

在过去,当我们使用 Java File 类删除或创建媒体文件时,我们必须通知操作系统以将其包含在媒体数据库中或从媒体数据库中删除。

现在我们不得不使用 DocumetFile 类来做一些事情......这个类提供了方法delete()createFile(String mimeType, String name).

我们是否必须再次通知操作系统使用

对于新文件和

用于文件删除或 DocumentFile 类自行完成?

我问的原因是因为 createFile() 方法需要 mimeType 作为输入。让我觉得它会使用 mimeType 来通知媒体数据库。

0 投票
2 回答
4933 浏览

android - Android - get DocumentFile with write access for any file path on sd card (having allready gained sd card permission)

In my app I gain sd card write permission using the following intent. If the user selects the sd card folder from the system file explorer then I have sd card write access.

After that I am able to modify files in th sd card using the DocumentFile class. But I'm having problem getting a DocumentFile for a random file path.

both return a DocumentFile object that returns false on .canWrite(). Even though I allready have sd card permission.

So I wrote the method posted in the end of my question to get a DocumentFile that returns true on .canWrite(). But this is slow...And also feels very wrong! There has to be a better way to do this. I also wrote a method that returns the same string as

for any file, where docFile is the DocumentFile that is returned by the method below. But

returns a DocumentFile that points to the root of the sd card instead of the DocumentFile path. Which is just weird. Can someone suggest a more elegant solution?

0 投票
1 回答
28010 浏览

android - 使用 SAF(存储访问框架)的 Android SD 卡写入权限

经过大量关于如何在 SD 卡(android 5 及更高版本)中写入(和重命名)文件的发现后,我认为 android 提供的新 SAF 将需要获得用户的权限才能写入 SD 卡文件。

我在这个文件管理器应用程序ES 文件资源管理器中看到,最初它通过以下方式获取读写权限,如图所示。

在此处输入图像描述

图二

选择sd卡后,授予写权限。

因此,我以同样的方式尝试使用 SAF,但重命名文件失败。我的代码:

仍然在运行代码后,我得到 EAacces 权限被拒绝。

0 投票
2 回答
2609 浏览

android - SAF DocumentFile - 检查路径是否存在而不在每个文件夹级别创建每个 DocumentFile

成像,您想检查“/folder/subfolder/subsubfolder/test/test.txt”文件是否存在,您可以执行以下操作:

这很慢,有没有更快的方法至少检查 SD 卡上是否存在文件?我不想创建每个DocumentFile只是为了检查路径是否存在......

0 投票
0 回答
895 浏览

android - AUDIO_OUTPUT_FLAG_FAST 被客户端拒绝 - Intent.ACTION_OPEN_DOCUMENT_TREE

我想从 mysdcard 中选择一个文件(然后我上传到服务器)。我尝试使用 Intent.ACTION_OPEN_DOCUMENT_TREE 来选择使用这篇文章的文件:

如何使用为 Android 5.0 (Lollipop) 提供的新 SD 卡访问 API?

但是当我尝试选择文件时,这是我从 Android Studio 收到的消息:

1489-1563/system_process W/AudioTrack:AUDIO_OUTPUT_FLAG_FAST 被客户端拒绝

我在网上搜索过,我点击的项目上似乎没有 OnclickListener (?)。

这是我用来选择文件的代码:

以及我如何处理响应:

我的错误在哪里?对不起,但我是新来的 android!

0 投票
2 回答
1714 浏览

android - ContentResolver doesn't contain just created image in an immediate query after creation of file

I'm using this code to copy an image using documentFile.createFile()

And this is how I query ContentResolver after creating image, to immediately refresh my image gallery with the result of query which should contain info of newly created image.

But immediate query couldn't find newly created image. And if I run query again after a moment, newly created image is there in the result.

It seems providing information for newly created image takes time for ContentResolver(if ContentResolver is in charge for it) as it would be running in background while I run immediate query.

Is there any method or listener to know when the newly created image is registered by ContentResolver?

0 投票
2 回答
4159 浏览

java - Android DocumentFile 无效的 URI

我正在尝试使用 DocumentFile 在我的 android 5.1 手机上列出外部存储设备中的文件

这段代码工作正常,但我想这样做;

但我得到这样的例外:

0 投票
4 回答
6934 浏览

android - 是否可以从 DocumentFile 获取常规文件?

对于 Android,以下代码返回一个 Uri,可用于创建与目录对应的 DocumentFile。

由于库的许多方法需要一个参数是 java.io.File,我想知道是否可以从 DocumentFile 中获取 java.io.File。

例如,返回的文档树 Uri treeUri 如下:

以下是 ADM 中显示的目录: 在此处输入图像描述

0 投票
1 回答
1159 浏览

java - Java中File和DocumentFile的区别

Java Android 中的 ajava.util.File和 a到底有什么区别?android.support.v4.provider.DocumentFile