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
1
vote
0 answers

Can I create a DocumentFile with a stored Uri?

I got a Uri using the following method. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, MY_REQUEST_CODE); like: content://com.android.externalstorage.documents/tree/primary%3A Can I store this string to…
nolizemin
  • 11
  • 3
1
vote
1 answer

How to rewrite DocumentFile

I want to let user to pick up folder and my app will make a file in this folder. So I use Intent.ACTION_OPEN_DOCUMENT_TREE. Google says that I need to use DocumentFile instead of File. Previously I used File and want to get the result similar to…
Valgaal
  • 896
  • 10
  • 25
1
vote
1 answer

Why does DocumentFile.getParentFile() return null after it is created with a Uri?

Code: DocumentFile dfNew = dfDirectory.createFile("video/mp4", "foo.mp4"); //dfNew.getParentFile() is NOT null. DocumentFile dfNewCopy = DocumentFile.fromSingleUri(activity, dfNew.getUri()); //dfNewCopy.getParentFile() IS null. Otherwise,…
Hong
  • 17,643
  • 21
  • 81
  • 142
1
vote
0 answers

Android: Strange behavior of DocumentFile InputStream

Background I have an application that uses Storage Access Framework. It prompts a user to pick a directory to obtain permissions to work with files: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); Then allow user to select a JPG image…
Quark
  • 1,578
  • 2
  • 19
  • 34
1
vote
1 answer

Writing with an OutputStream to a DocumentFile: data seem to be written but file ends up empty

The application KDE Connect allows remotely browsing an Android device from a desktop computer through SFTP. Since Android 4.4, developers don't have write permission to SD cards directly through the filesystem anymore. So I am trying to port the…
1
vote
1 answer

Explore contents of Uri Folder retrieved from Intent.ACTION_OPEN_DOCUMENT

I want to be able to access the list of files from a DocumentFile, when the user selects a folder instead of a file. I am calling the intent like this: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); …
pwoolvett
  • 524
  • 4
  • 13
1
vote
1 answer

Android: How to get permanent write permission on removable sd-card?

I went through the Storage Access Framework for the last days and still don't get it. My Question is: How can I create a file with those permissions on the sd-card without beeing prompt to select a patha after selecting the sd-card location once? I…
MSeiz5
  • 182
  • 1
  • 9
  • 28
1
vote
0 answers

DocumentFile rename latency

In my application I have original file on SD card, I create temporal file on SD card using DocumentFile, write some data there and finaly want to replace original file with temporal one. Using DocumentFile I'm deleting original file with delete()…
1
vote
0 answers

Unable to append bytes at the end of the file in SD card - Lollipop

I am building a downloading manager to download files and save it to my sd card. For API>=23, I have to use FileOutputStream, which help me to resume the file in case downloading fails. However, in API 21 & API 22 (Lollipop), one can't write in Sd…
1
vote
1 answer

How to perform basic operations on files using DocumentFile API?

Background Starting from API 21 (Lollipop), apps can get a special "permission" to modify real SD-cards, as shown on previous posts I've written (here and here). The problem I can delete files, and I can also create them, but I can't find a way to…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
1
vote
1 answer

Saving files to SD card on Android Lollipop

Android 5 introduce new API for working with SD-card. If you want to write files into some directory on the SC-card, y need get access to it. As far as I know, it could be done in this way: Intent intent = new…
0
votes
0 answers

Android get folder of single DocumentFile (uriForFile)

I have big trouble to get the directory that contains a users picked file. The file contains the information for the directory. So I have to read it and then work with tbe files in that directory. The question is how I get from the DocumentFile…
Oschi
  • 1
0
votes
0 answers

Can't use DocumentsContract.getDocumentId on uri gotten from ActivityResultContracts.OpenDocumentTree()

From here: https://stackoverflow.com/a/70933975/13519865 if I, private val dirRequest = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri -> if (uri != null) { DocumentsContract.getDocumentId(uri) } } I…
0
votes
0 answers

Android app: Differentiate "folder deleted" from "permission removed" for this folder

In my Android app, the user can select a folder thanks to Intent.ACTION_OPEN_DOCUMENT_TREE I can then write files to this folder. The problem is that the user can delete this folder or remove the permission to access it. In both cases, I would like…
Laurent D.
  • 449
  • 4
  • 19
0
votes
3 answers

opening an external "file explorer" app: how to get absolute path from a uri pointing to a folder

In my app, the user can choose where the created files (text files) are created. This part is working fine. But now, I want to open an external "file explorer" app, pointing directly to the chosen folder. The "file explorer " apps I know accept an…
Laurent D.
  • 449
  • 4
  • 19