Search code examples
androidstorage-access-framework

How to recreate a DocumentFile folder from a previous URI


If we create a DocumentFile using the tree URI returned from ACTION_OPEN_DOCUMENT_TREE.

DocumentFile dir = DocumentFile.fromTreeUri(context, treeUri);

And then create a sub directory

DocumentFile subDir = pickedDir.createDirectory("example");
Uri uri = subDir.getUri();

How can we later recreate the sub directory using the above URI?


Solution

  • Figured it out, you have to use DocumentsContract.createDocument() with the URI of the previously created directory.