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
125
votes
3 answers

How to use the new SD card access API presented for Android 5.0 (Lollipop)?

Background On Android 4.4 (KitKat), Google has made access to the SD card quite restricted. As of Android Lollipop (5.0), developers can use a new API that asks the user to confirm to allow access to specific folders, as written on the this…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
26
votes
2 answers

How to get access to all SD-cards, using the new Lollipop API?

background Starting with Lollipop, apps can get access to real SD-cards (after it was not accessible on Kitkat, and was not officially supported yet worked on previous versions), as I've asked about here. The problem Because it has become quite rare…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
25
votes
1 answer

Android SD Card Write Permission using SAF (Storage Access Framework)

After a lot of findings about how to write(and rename) a file in SD Card (android 5 and above), I think the new SAF provided by android will be required to take permission from user to write SD card file. I have seen in this File Manger Application…
19
votes
6 answers

Android 5.0 DocumentFile from tree URI

Alright, I've searched and searched and no one has my exact answer, or I missed it. I'm having my users select a directory by: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, READ_REQUEST_CODE); In my…
Joe Walton
  • 191
  • 1
  • 1
  • 4
12
votes
1 answer

Bug when listing files with Android Storage Access framework on Lollipop

Background I have a few apps that make heavy use of SD card for file syncing. The broken external SD card access on Kitkat is still a big problem, but I am trying to resolve this with the new API available on Lollipop for the users which have…
AndersC
  • 512
  • 1
  • 4
  • 11
11
votes
1 answer

How to get random access to a file on SD-Card by means of API presented for Lollipop?

My application uses Java class RandomAccessFile to read/write bytes to a file on SD card randomly by means of realization of SeekableByteChannel interface. Now I need rewrite it for Android 5.0 with new Lollipop API. I have found the only way to…
10
votes
1 answer

Correctly delete DocumentFile (respecting the MediaStore)

I have a DocumentFile defined in following two ways: DocumentFile documentFile; Uri documentFileUri; I can delete a document file from the sd card via following methods: documentFile.delete(); DocumentsContract.deleteDocument(contentResolver,…
prom85
  • 16,896
  • 17
  • 122
  • 242
9
votes
1 answer

Storage Access Framework Getting Correct Uri Path Delete/Edit/Get File

TL:DR; I explained how to use create folders and subfolders using DocumentFile and how to delete file created using this class. Uri returned from onActvityResult() and documentFile.getUri.toString() are not same. My question is how to get a valid…
Thracian
  • 43,021
  • 16
  • 133
  • 222
8
votes
4 answers

Is it possible to get a regular File from DocumentFile?

For Android, the following code returns a Uri that can be used to create DocumentFile corresponding to a directory. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_CUSTOM_FOLDER); Since many…
Hong
  • 17,643
  • 21
  • 81
  • 142
8
votes
2 answers

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. Intent intent = new…
Anonymous
  • 4,470
  • 3
  • 36
  • 67
7
votes
2 answers

Android DocumentFile invalid URI

i am trying to list files in external storage devices on my android 5.1 phone using DocumentFile String rootPathURI = "file:/media/storage/sdcard1/data/example.externalstorage/files/"; File f = new File(URI(rootPathURI)); DocumentFile documentFile…
Tom
  • 173
  • 2
  • 13
7
votes
2 answers

Storage Access Framework - set last modified date of local DocumentFile

I want to copy or move files from the internal storage to the sd card. I do this via the Storage Access Framework (SAF) and the DocumentFile class... Copying is stream based and the DocumentFile does not have a function like the File class to set…
prom85
  • 16,896
  • 17
  • 122
  • 242
6
votes
2 answers

DocumentFile.exists() on a path that doesn't yet exist always returns true due to DocumentFile().fromTreeUri()

I'm trying to check if a file exists prior to creating it, using DocumentFile (due to the Storage Access Framework). But DocumentFile().fromTreeUri() removes the non-existant portion of the would-be Uri, which then causes DocumentFile().exists() to…
Duncan McArdle
  • 501
  • 5
  • 14
6
votes
2 answers

SAF DocumentFile - check if path exists without creating each DocumentFile at each folder level

Imaging, you want to check if "/folder/subfolder/subsubfolder/test/test.txt" file exits, you would do following: DocumentFile sdCard = ...; // i have already retrieved the sd card root with the users help via SAF String path = "
prom85
  • 16,896
  • 17
  • 122
  • 242
6
votes
0 answers

How to set Last Modified File attribute using new SD-Card access API for Android 5.0?

Background: Using: ACTION_OPEN_DOCUMENT_TREE + DocumentFile More on: How to use the new SD card access API presented for Android 5.0 (Lollipop)? I would like to ask: I cannot find the way how to change file attributes. Is there any? Particularly, I…
Quark
  • 1,578
  • 2
  • 19
  • 34
1
2 3 4 5 6 7