In my App the user can choose a directory where to create an Excel file using the implicit intent ACTION_OPEN_DOCUMENT_TREE.
However, the Uri returned in onActivityRes
Step #1: Take the Uri
that you get from ACTION_OPEN_DOCUMENT_TREE
and pass it to DocumentFile.fromTreeUri().
Step #2: Call createFile() on that DocumentFile to get a DocumentFile
representing the child document.
Step #3: Call getUri() on the DocumentFile that you created in Step #2.
Step #4: Call openOutputStream() on a ContentResolver, passing in the Uri
from Step #3, to get an OutputStream
that you can use to write content. You get a ContentResolver
by calling getContentResolver()
on some Context
, such as an Activity
.
See this blog post for more on using ACTION_OPEN_DOCUMENT_TREE
.