问题标签 [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.
android - 我可以使用存储的 Uri 创建 DocumentFile 吗?
我使用以下方法得到了一个 Uri。
喜欢:</p>
我可以存储此字符串以在应用程序启动时创建 DocumentFile 吗?喜欢:
它适用于Android 6.0,但在更高版本中似乎无效。还是每次启动时都应该获取 Uri?我发现有些文件管理器不需要通过 startActivityForResult() 来获取 Uri。像RE。他们是在使用 shell 获取 /storage 下的列表,然后将它们拼接到 Uri 中吗?
然后使用grantUriPermission()和takePersistableUriPermission()获取Uri权限?
对不起,我的英语太差了。TT
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
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 ..
nullpointerexception - 在列表文件方法中获取空指针异常?
我正在尝试DocumentFile[]
使用方法检索所有内容。listFiles()
但是获取空指针异常如何消除此错误并仍然获取文件。这是搜索作为 documentfile
方法参数传递的 sd 卡根目录的代码。
java - 为什么我需要写权限外部存储来删除文件?
我的问题是为什么我在尝试从 sdcard 中删除文件时需要此权限,因为权限显示为“写入”,当我尝试删除某些内容时它不会向 sdcard 写入任何内容,那么为什么需要这个权限?
我尝试删除权限,但没有它没有任何效果。
WRITE_EXTERNAL_STORAGE 是一个危险的权限,我需要将其包含在我的隐私政策中,我不知道如何解释这一点。
我的权限
我删除文件的代码
删除文件方法
这是我在这里的另一篇文章中使用的代码
android - SAF - DocumentsContract.createDocument 方法中的无效 URI 错误(FileOutputStream 副本)
我的应用程序正在迁移到 SAF,或者至少正在进行一些实验。
现在它必须将文件从私有应用程序文件夹复制到授权的 SAF 文件夹。
使用的方法是:
我明白了
该文件夹是通过以下方法创建的:
如您所见,之前版本的创建已被注释,因为它不起作用。有必要使用 DocumentFile,但似乎与 DocumentsContract 不兼容。我错了吗?
那么SAF坏了吗?还是我在绕圈子?
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
android - SAF - 检查文件夹 Uri 存在的方法总是产生 true
我的 Android 应用程序必须检查文件系统上是否已存在文件夹 Uri(父文件夹已由用户选择,因此已获得授权)。以下代码旨在执行检查:
此代码不起作用,因为如果文件夹不存在(从未创建,或创建和删除),即使父文件夹本身不存在,它也会产生真值。
请注意,该 uri 肯定还不存在。我使用设备上的文件系统应用程序来检查目录。
uri 字符串是通过以下方法创建的:
如您所见,生成的 uri 是包含编码和非编码符号的混合形式,因此它是合法的,因为 SAF 方法创建了完整的 uri。
不同版本的 folderExists 方法将 uri 字符串拆分为具有父文件夹。但我认为应该在没有这个技巧的情况下验证 uri。为什么它不起作用?什么是正确的代码?
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:
- User selects a file from a ACTION_OPEN_DOCUMENT_TREE
- Source file's type is obtained
- New DocumentFile in target location is initialised
- 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.
- The file size has changed from 2261840 to 2262016 (+176)
- 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.