问题标签 [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 投票
0 回答
45 浏览

android - 我可以使用存储的 Uri 创建 DocumentFile 吗?

我使用以下方法得到了一个 Uri。

喜欢:</p>

我可以存储此字符串以在应用程序启动时创建 DocumentFile 吗?喜欢:

它适用于Android 6.0,但在更高版本中似乎无效。还是每次启动时都应该获取 Uri?我发现有些文件管理器不需要通过 startActivityForResult() 来获取 Uri。像RE。他们是在使用 shell 获取 /storage 下的列表,然后将它们拼接到 Uri 中吗?

然后使用grantUriPermission()和takePersistableUriPermission()获取Uri权限?

对不起,我的英语太差了。TT

0 投票
0 回答
178 浏览

android - DocumentFile.renameTo 通过图库共享文件时使用旧文件名

我有一个重命名图像的应用程序,并使用 Document Fileprovider 来重命名外部存储上的文件。重命名工作正常,当我通过文件管理器检查文件名时,以及当我在 Google 照片应用程序中查看“信息”时,新文件名显示。但是,当我通过 Google 照片共享文件并选择“邮件”时,附件会选择旧文件名。

我尝试使用以下方法更新媒体存储:

或者

...还尝试了 Playstore 中的一些第 3 方媒体扫描仪。也重新启动,因为这也会触发媒体扫描。

但问题仍然存在。

添加了一些显示我描述的问题的图像

文件应用程序中的正确文件名

在 Google 照片应用程序的信息对话框中更正文件名

通过 Google 照片作为邮件附件分享照片后,旧的 Filaname 不正确

0 投票
0 回答
190 浏览

java - 获取 treeUri 子文件夹内的文件 uri

我正在尝试使用 TreeUri 目录的子文件夹内的循环获取文件/文件夹的 uri。

这是路径/storage/0018-E24D 的 treeUri

内容://com.android.externalstorage.documents/tree/0018-E24D%3A

该文件位于 treeUri 子文件夹中,路径为/storage/0018-E24D/apks/Admission deposit Slip-2019.pdf

我的代码如下

OnActivityShow

但我未能获得该文件的 uri

0 投票
1 回答
328 浏览

android - 将文档文件与存储访问框架一起使用

我从意图的结果数据中得到了 treeUri。我选择了 sdcard 的根路径。将 treeUri 转换为字符串类型的结果是content://com.android.externalstorage.documents/tree/C4FD-B5C6%3A.

问题 1。

这样的结果对吗?

问题2。

无论如何,我像这样创建了 Documentfile。

DocumentFile tree = DocumentFile.fromTreeUri(MusicServiceActivity.getAppContext(),Uri.parse(stringtreeUri));.

我打印了

tree.canWrite

使用 Log.e,但它总是返回 false。

我怎样才能使它返回真实?

添加

这是我的 onActivityResult ..

0 投票
0 回答
23 浏览

nullpointerexception - 在列表文件方法中获取空指针异常?

我正在尝试DocumentFile[]使用方法检索所有内容。listFiles()但是获取空指针异常如何消除此错误并仍然获取文件。这是搜索作为 documentfile方法参数传递的 sd 卡根目录的代码。

0 投票
3 回答
812 浏览

java - 为什么我需要写权限外部存储来删除文件?

我的问题是为什么我在尝试从 sdcard 中删除文件时需要此权限,因为权限显示为“写入”,当我尝试删除某些内容时它不会向 sdcard 写入任何内容,那么为什么需要这个权限?

我尝试删除权限,但没有它没有任何效果。

WRITE_EXTERNAL_STORAGE 是一个危险的权限,我需要将其包含在我的隐私政策中,我不知道如何解释这一点。

我的权限

我删除文件的代码

删除文件方法

这是我在这里的另一篇文章中使用的代码

Android SAF(存储访问框架):从 TreeUri 获取特定文件 Uri

0 投票
1 回答
1370 浏览

android - SAF - DocumentsContract.createDocument 方法中的无效 URI 错误(FileOutputStream 副本)

我的应用程序正在迁移到 SAF,或者至少正在进行一些实验。

现在它必须将文件从私有应用程序文件夹复制到授权的 SAF 文件夹。

使用的方法是:

我明白了

该文件夹是通过以下方法创建的:

如您所见,之前版本的创建已被注释,因为它不起作用。有必要使用 DocumentFile,但似乎与 DocumentsContract 不兼容。我错了吗?

那么SAF坏了吗?还是我在绕圈子?

0 投票
1 回答
49 浏览

android - SAF - 解码的 Uris 似乎被认为与 SAF 方法编码的 Uris 不同

我正在尝试在我的 Android 应用程序中引入 SAF。

似乎许多 SAF 方法的 uris 都是编码形式,例如:或 / 等字符被 %3A 和 %2F 替换。

在我的应用程序中,我正在解码 uris,因此它们具有以下形式:

content://com.android.providers.downloads.documents/tree/raw:/storage/emulated/0/Download/foldername

存储它们。

也许是错的。所以我问当传递从我的应用程序归档形式的字符串解析的 uri 时,SAF 方法是否被欺骗,也就是说,使用真正的字符,如:和/

像这样的方法:

它有

parentFolderUriStringParam=content://com.android.providers.downloads.documents/tree/raw:/storage/emulated/0/Download/foldername

oldParentUri="content://com.android.providers.downloads.documents/tree/raw:/storage/emulated/0/Download/foldername"

id="原始:"

parentFolderUri=content://com.android.providers.downloads.documents/tree/raw%3A/document/raw%3A/children

0 投票
3 回答
646 浏览

android - SAF - 检查文件夹 Uri 存在的方法总是产生 true

我的 Android 应用程序必须检查文件系统上是否已存在文件夹 Uri(父文件夹已由用户选择,因此已获得授权)。以下代码旨在执行检查:

此代码不起作用,因为如果文件夹不存在(从未创建,或创建和删除),即使父文件夹本身不存在,它也会产生真值。

请注意,该 uri 肯定还不存在。我使用设备上的文件系统应用程序来检查目录。

uri 字符串是通过以下方法创建的:

如您所见,生成的 uri 是包含编码和非编码符号的混合形式,因此它是合法的,因为 SAF 方法创建了完整的 uri。

不同版本的 folderExists 方法将 uri 字符串拆分为具有父文件夹。但我认为应该在没有这个技巧的情况下验证 uri。为什么它不起作用?什么是正确的代码?

0 投票
1 回答
198 浏览

java - Copied DocumentFile has different siize and hash to original

I'm attempting to copy / duplicate a DocumentFile in an Android application, but upon inspecting the created duplicate, it does not appear to be exactly the same as the original (which is causing a problem, because I need to do an MD5 check on both files the next time a copy is called, so as to avoid overwriting the same files).

The process is as follows:

  1. User selects a file from a ACTION_OPEN_DOCUMENT_TREE
  2. Source file's type is obtained
  3. New DocumentFile in target location is initialised
  4. Contents of first file is duplicated into second file

The initial stages are done with the following code:

The main copy process is done using the following snippet:

The problem that I'm facing, is that although the file copies successfully and is usable (it's a picture of a cat, and it's still a picture of a cat in the destination), it is slightly different.

  1. The file size has changed from 2261840 to 2262016 (+176)
  2. The MD5 hash has changed completely

Is there something wrong with my copying code that is causing the file to change slightly?

Thanks in advance.