documentfile

How to perform basic operations on files using DocumentFile API?

这一生的挚爱 提交于 2020-01-25 00:11:07
问题 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 perform other basic file operations: read, write, using InputStream and OutputStream move files. create a folder and not just a file rename a file get file info (recent updated,etc...) share/open the file via other apps. other operations I might

Creating a writeable DocumentFile from URI

廉价感情. 提交于 2020-01-24 19:44:05
问题 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 Uri as expected, which I can then handle using: getContentResolver().takePersistableUriPermission(resultData.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); I can browse successfully through the external

How to get child TreeDocumentFile from child Uri?

橙三吉。 提交于 2020-01-24 19:32:47
问题 [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 childTree = rootTree.createDirectory("ChildDir1") // childTree.name == "ChildDir1" val childUriStr = childTree.uri.toString() I store childUriStr into local database so I can later recreate childTree . childUriStr contains all elements needed: authority ,

How to get child TreeDocumentFile from child Uri?

这一生的挚爱 提交于 2020-01-24 19:32:10
问题 [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 childTree = rootTree.createDirectory("ChildDir1") // childTree.name == "ChildDir1" val childUriStr = childTree.uri.toString() I store childUriStr into local database so I can later recreate childTree . childUriStr contains all elements needed: authority ,

Android 5.0 DocumentFile from tree URI

江枫思渺然 提交于 2020-01-09 09:39:49
问题 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 activity I want to capture the actual path, which seems to be impossible. protected void onActivityResult(int requestCode, int resultCode, Intent intent){ super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { if

Bug when listing files with Android Storage Access framework on Lollipop

安稳与你 提交于 2019-12-20 10:24:12
问题 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 this. I successfully request and persist permission to SD card and I can list files in the root Uri returned from the grant permission activity. See more info on how this is done here: how-to-use-the-new-sd-card-access-api-presented-for-lollipop The user

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

久未见 提交于 2019-12-17 22:15:10
问题 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 to see a Lollipop device that supports SD-card and because the emulator doesn't really has the ability (or does it?) to emulate an SD-card support, it took me quite a while to test it. Anyway, it seems that instead of using the normal File classes

Convert File to DocumentFile

亡梦爱人 提交于 2019-12-11 17:47:33
问题 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 returns not correct Uri : file:///storage/A54E-14E9/bp.mp4 So it's different than when you get it in onActivityResult after calling startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), REQUEST_CODE_STORAGE_ACCESS); @Override

Writing EXIF data to image saved with DocumentFile class

与世无争的帅哥 提交于 2019-12-08 01:52:58
问题 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 file:///storage/emulated/0 or storage/emulated/0 but i could not find a way to get correct Uri for building a File to write EXIF data to image. My scenario is: User chooses a path to save images which returns Uri with content://com.android

Writing EXIF data to image saved with DocumentFile class

只愿长相守 提交于 2019-12-06 07:27:25
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 file:///storage/emulated/0 or storage/emulated/0 but i could not find a way to get correct Uri for building a File to write EXIF data to image. My scenario is: User chooses a path to save images which returns Uri with content://com.android.externalstorage.documents onActivityResult(). I save this path with treeUri.toString() to SharedPreferences for