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
5
votes
4 answers

DocumentFile RandomAccessFile

Is there any way get a RandomAccessFile from a given DocumentFile? I know it is possible to get an InputStream via getUri InputStream inputStream = getContentResolver().openInputStream(DocumentFile.getUri()); But I need a RandomAccessFile Thanks…
JensSommer
  • 51
  • 2
4
votes
2 answers

How to fetch files inside hidden folder using Media Store API on Android 11

I need to fetch data inside WhatsApp folders on External Storage. As i am targeting API Level 30 i am no longer able to access WhatsApp folders on External Storage. I have implemented Storage Access Framework and got Android/media folder Uri and…
4
votes
1 answer

How to write to DocumentFile in Android programmatically?

Android API has DocumentFile class. This class has canWrite() method. Suppose I called this method and it returned true. Also suppose this object was representing "raw" file. Now how can I do what it said I can? Namely, how to write "Hello world"…
Dims
  • 47,675
  • 117
  • 331
  • 600
4
votes
1 answer

Check that a DocumentFile exists

I check a files meta data and existence using DocumentFile. This is instanciated thusly: DocumentFile df = DocumentFile.fromSingleUri(context, uri); boolean exists = df.exists(); The uri to the file worked previously, until I purposefully deleted…
Knossos
  • 15,802
  • 10
  • 54
  • 91
4
votes
1 answer

Android Marshmallow: Files written by SAF are not immediatelly written

I am using SAF (Storage access framework) to write files to SD card. On Marshmallow, the files are actually written and updated with a big delay (approximately 10 seconds). When I use e.g.: android.support.v4.provider.DocumentFile docFile =…
4
votes
2 answers

Refresh gallery using MediaScanner connection with DocumentFile URI obtained from TreeUri for Lollipop version

Hi i am trying to refresh gallery by initiating a scan. For devices running Kitkat and higher versions i am using mediascannerconnection. But the mediaScannerConnection needs absolute path to do scan. What i have is a DocumentFile which does not…
3
votes
1 answer

Walking a DocumentFile tree

I'm trying to walk an Android DocumentFile tree recursively but I cannot get a list of files to be returned for a subfolder. When I attempt listFiles() on the folder URI, I get the list of root files returned each time. Why is this not…
SparkyNZ
  • 6,266
  • 7
  • 39
  • 80
3
votes
1 answer

Sort array of DocumentFiles faster in Android

In this case I have to sort hundreds of DocumentFile objects using this method: DocumentFile[] files = documentFile.listFiles(); ArrayList docFiles = new ArrayList(); …
Matt Riley
  • 33
  • 3
3
votes
0 answers

Convert File to DocumentFile

I want to convert File (/storage/A54E-14E9/bp.mp4) to DocumentFile Uri of DocumentFile should be content://com.android.externalstorage.documents/tree/A54E-14E9%3A/document/A54E-14E9%3Abp.mp4 but when I use DocumentFile.fromFile(file).getUri() it…
user155
  • 775
  • 1
  • 7
  • 25
3
votes
1 answer

Writing EXIF data to image saved with DocumentFile class

I need to get a File from DocumentFile or Uri with correct scheme not the one with content://com.android.externalstorage.documents/tree/primary: if the device's main memory is selected. To get File or absolute path of the image i need the one with…
Thracian
  • 43,021
  • 16
  • 133
  • 222
3
votes
2 answers

Get a DocumentFile that is a child of a document tree without using findFiles()

I have a tree URI that I got from ACTION_OPEN_DOCUMENT_TREE, how can I get a DocumentFile that is a child of this tree without using findFiles()? Given that I know how to get its documentId, its absolute path or its URI. I need the permissions…
jeanv
  • 53
  • 8
3
votes
0 answers

Android - do file operations using DocumentFile class require alerting the MediaScanner?

I tried to follow the source code for this and spare the post but I kind of got lost there.. In the old days when we deleted or created a media file using the Java File class we had to notify the OS about it to include it in or remove it from the…
2
votes
0 answers

Android 11: ACTION_OPEN_DOCUMENT_TREE get absolute Folder Path

Since Android 11 restricts the freedom accesing the external storage, I've looked many solutions to convert following path which I receive from ACTION_OPEN_DOCUMENT_TREE intent:…
2
votes
2 answers

Android 11: DocumentFile findFile() is too slow

With this update of Google's storage policy, I had to change the way I save files. First, my application previously saved the project folder to /sdcard/. However, due to this policy, access using File became impossible, and I tried several…
rosered65
  • 75
  • 1
  • 6
2
votes
1 answer

Can't convert Uri to String and String to Uri again

I am working on a music player and want to use Storage access framework to access the files in the storage. For that I used Intent.ACTION_OPEN_DOCUMENT_TREE and contentResolver.takePersistableUriPermission(...). But once I've got the permissions, I…