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
0
votes
0 answers

Check DocumentFile is editable text file or not in Android java

var documentFile = DocumentFile.fromSingleUri(this,uri); if(documentFile.isFile() && isEditableFileType(documentFile.getType())){ BaseApp.showToast("Y=> "+documentFile.getType()); }else{ …
Sue007
  • 21
  • 2
0
votes
1 answer

Android 11 - Unable to copy file, 'NO_SPACE_LEFT_ON_TARGET_PATH' despite having a lot of space using SimpleStorage API

I am making a file backup program, using ACTION_OPEN_DOCUMENT_TREE my user picks a folder, then my intent is to copy all items in that folder to the tablet, I do this by saving the URI of the folder the user selects in variable TheURI, I then…
0
votes
1 answer

How to rewrite DocumentFile completely

I want to open/create a document file and rewrite it completely if it exists. Using How to rewrite DocumentFile does not help (at least in API 32). In fact, OutputStream os = getContentResolver().openOutputStream(documentFile.getUri(), "w"); does…
Alex B
  • 347
  • 1
  • 3
  • 9
0
votes
0 answers

Opening large SQLite Databases on Android 11

I need to open a large SQLite Database on Android 11 (api level 30). The Documentation says that "MANAGE_EXTERNAL_STORAGE" is a Problem in the Future. Therefore, I read the Docs at:…
0
votes
2 answers

How to get File from DocumentFile in android version 29+ for File Manager App?

I am developing File Manager, I have one issue in android version 30, when I get listFile() of OTG path its not return file, the only way to get all files is from DocumentFile, but now I want to get file as File from that DocumentFile how do I get,…
0
votes
0 answers

ContentResolver ignoring selection argument whne trying to find a documentfile by name

I'm trying to get a specific file by its name using the following code, however, it looks like the selection arguments are ignored as it always returns the 1st file of the root tree final ContentResolver resolver =…
user1026605
  • 1,633
  • 4
  • 22
  • 58
0
votes
1 answer

Update DATE_MODIFIED in MediaStore on Android 11 with DocumentFile TreeUri

I'm struggling to update metadata in the mediastore with a DocumentFile/TreeUri. This is how I tried to do it: boolean canWrite = documentFile.canWrite(); //returns true Uri mediaUri = MediaStore.getMediaUri(context,…
0
votes
1 answer

How to list subfolder content when using Android DocumentFile API

I'm trying to switch to the DocumentFile API as Android doesn't allow using File API anymore... When I select a folder, it returned URI is content://com.android.externalstorage.documents/tree/primary%3AMedia%2FCamera%2FFreeTime Now I'm calling …
user1026605
  • 1,633
  • 4
  • 22
  • 58
0
votes
0 answers

How to get a documentfile uri that doesn't exist yet?

I am trying to generate a Uri with a given file name that does not exist yet. I have asked for permission from the user to access this folder. Basically, I have a tree Uri and a name, say "untitled.abc". If untitled.abc already exists in the given…
erinys
  • 273
  • 1
  • 4
  • 18
0
votes
3 answers

Reading custom files on storage card for android sdk 30

I have an app that creates custom files that are shown in a gallery. They are not images or other standard media files. Because the files are large, I ask users for access to a folder in which the files will be stored. So far so good. Reading those…
erinys
  • 273
  • 1
  • 4
  • 18
0
votes
1 answer

takePersistableUriPermission Access lost after documentfile deleted

After picking a folder with registerForActivityResult( new ActivityResultContracts.OpenDocumentTree ... I'm taking writing permission on it getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION |…
Omkar T
  • 755
  • 8
  • 19
0
votes
1 answer

onActivityResult Uri - create subfolder and get DocumentUri of new subfolder

I take the result of my file chooer in onActivityResult an build a DocumentUriUsingTree. Now I take this DocumentUri, build a DocumentFile to create a new folder. onActivityResult: if (resultCode == RESULT_OK) { …
0
votes
0 answers

/tree/primary vs /document/primary

I am learning how to use SAF. In my demo application, I found out uri path could be /tree/primary and /document/primary. I want to know what is the difference?
Khamidjon Khamidov
  • 6,783
  • 6
  • 31
  • 62
0
votes
0 answers

Create DocumentFile from Uri

Using SAF I create a file in the file provider. In onActivityResult I then persist the permissions to that file and store the Uri into the shared preferences. Later I write data into the file. This seems to work. except if the file was…
Guiorgy
  • 1,405
  • 9
  • 26
0
votes
0 answers

How to use DocumentsProvider.moveDocument with TreeUri?

I want to move a DocumentFile from one Location to another. The Uris are aquired via ACTION_OPEN_DOCUMENTTREE and stored. However, when i try: val resolver = context.contentResolver val srcUri = Uri.parse(myUriFromACTION_OPEN_DOCUMENT_TREE) val…
sanlalala
  • 17
  • 4