Questions tagged [documentfile]

DocumentFile Class represent a document backed by either a DocumentsProvider or a raw file on disk.

This is a utility class designed to emulate the traditional File interface. It offers a simplified view of a tree of documents, but it has substantial overhead. For optimal performance and a richer feature set, use the DocumentsContract methods and constants directly.

93 questions
2
votes
1 answer

How to move a mediastore content item to another directory via DocumentContract.moveDocument()?

Since Android is enforcing the use of storage access framework by scoped storage accessing, app cannot use direct java.io.file operation to move files. The purpose is to move some specific media item which is queried from the mediastore database to…
2
votes
1 answer

How to get child's DocumentFile from Document Uri

Assume the following folder structure: - root -- Android -- Downloads -- .... -- Test --- Example ---- Dir1 Given the Uri listed below, how can I get the DocumentFile for the directory located at the /Test/Example path, where Test and Example are…
chris_z13
  • 21
  • 2
2
votes
2 answers

How to get child TreeDocumentFile from child Uri?

[Rewrite, based on comments] Simplified example: rootUri is obtained by ACTION_OPEN_DOCUMENT_TREE. Then I create a folder (or more nested folders): val rootTree = DocumentFile.fromTreeUri(context, rootUri) // rootTree.name == "treeRoot" val…
Jure Sencar
  • 554
  • 4
  • 13
2
votes
1 answer

Creating a writeable DocumentFile from URI

I'm trying to adapt a File-based document system to something using DocumentFile in order to allow external storage read/write access on API >= 29. I get the user to select the SD card root using Intent.ACTION_OPEN_DOCUMENT_TREE, and I get back a…
KT_
  • 978
  • 11
  • 26
2
votes
0 answers

DocumentFile.length() is extremely slow, want direct access to sd card

I want to give the user the option to save images on their sd card and I want to be able to calculate the sizes of folders of such images. I find that Environment.getExternalStorageDirectory() returns internal storage. The only way I can find the sd…
karnok
  • 1,202
  • 1
  • 12
  • 17
2
votes
1 answer

Difference between File and DocumentFile in Java

What's exactly the difference between a java.util.File and a android.support.v4.provider.DocumentFile in Java Android?
larsaars
  • 2,065
  • 3
  • 21
  • 32
2
votes
2 answers

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() private void newcopyFile(File fileInput, String outputParentPath, String mimeType, String newFileName) { DocumentFile documentFileGoal =…
2
votes
1 answer

How to manage all local storages in all versions (primary, secondary storage, sd card, usb)

Intro Managing primary storage files + secondary storage files (local only): I will list all the informations I already have and would like you to extend them or correct me so that this question hopefully becomes a overview that summarises all the…
prom85
  • 16,896
  • 17
  • 122
  • 242
1
vote
1 answer

What is the "authority" that DocumentsContract.moveDocument() needs?

I have a simple file inside either the apps getExternalFilesDir or a user selected folder. When i create a subfolder and try to move the file from the parent folder into that newly created subfolder moveDocument() fails. Logcat…
NikkyD
  • 2,209
  • 1
  • 16
  • 31
1
vote
1 answer

How can I read the contents of a DocumentFile in Android?

I have added a feature to an application to allow the user to create a local backup on external storage. That part is working great, but I am having trouble restoring that back up. Using the SAF, I have found an easy way for the user to select the…
1
vote
1 answer

How to delete files with DocumentFile in Android Q?

Method for deleting file with document uri private void getDocumentUri(Uri mediaUri){ try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && getActivity() != null) { Uri documentUri =…
Vince VD
  • 1,506
  • 17
  • 38
1
vote
1 answer

DocumentFile.createFile() failed on some Android 10 devices

DocumentFile.createFile() returns null ( java.lang.IllegalArgumentException ) on some Android 10 devices. Most of them are HUAWEI devices: VOG-L29, MAR-LX1A, ... Some users have reported this, but I can't figure out why. I don't have a device with…
Blue Ocean
  • 208
  • 2
  • 8
1
vote
1 answer

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…
Duncan McArdle
  • 501
  • 5
  • 14
1
vote
3 answers

SAF - method checking folder Uri existence yields always true

My Android app has to check whether a folder Uri is already present on the filesystem (the parent folder was selected by the user, so it is authorized). The following code is intendend to perform the check: static public boolean…
P5music
  • 3,197
  • 2
  • 32
  • 81
1
vote
0 answers

Getting null pointer exception in list Files method?

I am trying to retrieve all DocumentFile[] using listFiles() method.But getting a null pointer exception how to eliminate this error and still get the files. This is the code which searches sd card root directory which is being passed as …
sandeep K
  • 59
  • 8