问题标签 [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 - 检查 DocumentFile 是否存在
我使用 DocumentFile 检查文件元数据和存在。这是这样实例化的:
该文件的 uri 以前有效,直到我故意在文件系统中手动删除该文件以查看应用程序将如何反应。现在这个堆栈跟踪出现在应用程序中:
它不会使应用程序崩溃,它只会在我每次尝试使用 DocumentFile 时生成此堆栈跟踪。所以在最坏的情况下,这只是 logcat 中的一个刺激物。
我希望FileNotFoundException
使用.exists()
. 当我检查它是否存在以避免使用不存在的文件时。
在这种情况下是否推荐使用不同的功能?
android - Android - 使用 DocumentFile 类的文件操作是否需要提醒 MediaScanner?
我试图遵循源代码并保留这篇文章,但我有点迷路了..
在过去,当我们使用 Java File 类删除或创建媒体文件时,我们必须通知操作系统以将其包含在媒体数据库中或从媒体数据库中删除。
现在我们不得不使用 DocumetFile 类来做一些事情......这个类提供了方法delete()
和createFile(String mimeType, String name)
.
我们是否必须再次通知操作系统使用
对于新文件和
用于文件删除或 DocumentFile 类自行完成?
我问的原因是因为 createFile() 方法需要 mimeType 作为输入。让我觉得它会使用 mimeType 来通知媒体数据库。
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?
android - SAF DocumentFile - 检查路径是否存在而不在每个文件夹级别创建每个 DocumentFile
成像,您想检查“/folder/subfolder/subsubfolder/test/test.txt”文件是否存在,您可以执行以下操作:
这很慢,有没有更快的方法至少检查 SD 卡上是否存在文件?我不想创建每个DocumentFile
只是为了检查路径是否存在......
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!
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
?
java - Android DocumentFile 无效的 URI
我正在尝试使用 DocumentFile 在我的 android 5.1 手机上列出外部存储设备中的文件
这段代码工作正常,但我想这样做;
但我得到这样的例外:
java - Java中File和DocumentFile的区别
Java Android 中的 ajava.util.File
和 a到底有什么区别?android.support.v4.provider.DocumentFile