Feature description
termux-manage-folder: open a directory tree and returns the URI.
termux-saf-ls: lists directories and files in a folder as JSON, returning the URI and metadata, so you can navigate the document tree.
termux-saf-read: Reads a file from a URI and outputs it to stdout or a file.
termux-saf-write: Writes stdin to a file from a URI, or to a new file if the parent directory URI and a name is specified.
Example: termux-saf-read <URI to file on the sd card> | gzip | termux-saf-write <URI to folder on the sd card> compressed.gz
Another usage case for the user could be to periodically backup the home directory, compress it, encrypt it and safe it to google drive via SAF, completely automatic and without having to choose any location or moving the file yourself.
The difference to termux-storage-get is that the files don't need to be saved temporarily, so you can use streaming programs to process large files efficiently, and because the app gets the permission to use the directory tree forever, there is no need to open a UI when a command is run, you can automate reading and writing from the SAF from the command line.
You could also then make more high-level programs to build on top of that, e.g. storing all accessible folder URIs in a file and map them to paths and make utilities to work with those paths instead that internally call the URI-based programs, abstracting away the URIs and working with paths like dir1/some/folders/deep/file.txt, which is easier for the user to type.
It may also be possible to modify proot to "mount" a SAF directory, so you can access the files with programs that can't operate with stdin and stdout.
Reference implementation
Have you checked if the feature is accessible through the Android API?
https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE
https://developer.android.com/training/data-storage/shared/documents-files
Do you know of other open-source apps that has a similar feature as the one you want? (Provide links)
simple file manager uses that to get access to the sd card.
Feature description
termux-manage-folder: open a directory tree and returns the URI.
termux-saf-ls: lists directories and files in a folder as JSON, returning the URI and metadata, so you can navigate the document tree.
termux-saf-read: Reads a file from a URI and outputs it to stdout or a file.
termux-saf-write: Writes stdin to a file from a URI, or to a new file if the parent directory URI and a name is specified.
Example:
termux-saf-read <URI to file on the sd card> | gzip | termux-saf-write <URI to folder on the sd card> compressed.gzAnother usage case for the user could be to periodically backup the home directory, compress it, encrypt it and safe it to google drive via SAF, completely automatic and without having to choose any location or moving the file yourself.
The difference to
termux-storage-getis that the files don't need to be saved temporarily, so you can use streaming programs to process large files efficiently, and because the app gets the permission to use the directory tree forever, there is no need to open a UI when a command is run, you can automate reading and writing from the SAF from the command line.You could also then make more high-level programs to build on top of that, e.g. storing all accessible folder URIs in a file and map them to paths and make utilities to work with those paths instead that internally call the URI-based programs, abstracting away the URIs and working with paths like
dir1/some/folders/deep/file.txt, which is easier for the user to type.It may also be possible to modify proot to "mount" a SAF directory, so you can access the files with programs that can't operate with stdin and stdout.
Reference implementation
Have you checked if the feature is accessible through the Android API?
https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT_TREE
https://developer.android.com/training/data-storage/shared/documents-files
Do you know of other open-source apps that has a similar feature as the one you want? (Provide links)
simple file manager uses that to get access to the sd card.