termux-api
termux-api copied to clipboard
Rudimentary tools to write to the external sd card
Hi, last year we talked about rudimentary tools to write to the external sd card using the API here: https://plus.google.com/u/0/112187690141583660341/posts/a7vMDeZUENs I am just opening this here to track it and so it doesn't get forgotten.
Something like termux-cp
, termux-mv
and termux-rm
could be implemented into the API and the Java app can then do the proper calls to Android API and copy, move or delete the files.
Thanks for opening this issue @Neo-Oli this topic is in line with "Does Anyone Want to Have More Native Space on Device? #1176" and "Feature Request: mount loopback device #376" and "Is it possible to grant permission for Termux to use loop devices? #375" too.
So I recently upgraded to a new (Android 10) phone, and was disappointed to find that I could not write files to the external SD card that other applications could access. I understand that the key reasons are described [here:] (https://wiki.termux.com/wiki/Internal_and_external_storage) "SAF-based access is not possible as shell is executed outside of Android framework", as well as [this reddit thread.] (https://www.reddit.com/r/termux/comments/dcmdpg/is_there_a_workaround_to_access_all_of_my_sd_card/f2eza5y?utm_source=share&utm_medium=web2x&context=3)
Getting some rudimentary write access through the API would be useful to me, but I am not up to implementing it myself right now. In case it helps anyone else, my current work around is to install a file server app that supports SAF write access to the external SD card ('primitive ftpd' supports sftp and is in f-droid), and access that in my scripts within termux. This isn't as clean as something built in to the API, but works well enough.
@innolee you can read/write to your media folder on the sdcard at /storage/XXXX-XXXX/Android/media/com.termux. Other apps can access this folder, unlike the data folder, and while it's likely intended for media files, nothing stops me from downloading files to it.
If you already have a large number of files in your external data folder, do note that there's no filesystem permissions issue with accessing the location; simply renaming the Android or data folder will allow access with a file manager.Just make sure you remember to rename it back before opening an app that needs it.
Rudimentary tools to write to the external sd card
DutchOfBurdock shared a good potential resolution last week. The (hidden) Android™ file manager is accessable with this command: am start -a android.intent.action.VIEW -d "content://com.android.externalstorage.documents/root/primary"
This does not resolve the original issue. While Android embedded file manager allows operations in Termux home directory (thanks to Termux document provider implementation), it is not same as proposed tools termux-cp
, termux-mv
, termux-rm
and similar.
For now we only have termux-storage-get
which is used for retrieving files (https://wiki.termux.com/wiki/Termux-storage-get).
This does not resolve the original issue.
I must agree with the statement above as the command am start -a android.intent.action.VIEW -d "content://com.android.externalstorage.documents/root/primary"
changes the CLI user interface into a (hidden) Android™ file manager GUI user interface.
could be implemented into the API and the Java app can then do the proper calls to Android API and copy, move or delete the files.
Can simple shell scripting suffice in resolving this topic like in this live online example, in opposition to using higher level languages such as java and similar?
@innolee you can read/write to your media folder on the sdcard at /storage/XXXX-XXXX/Android/media/com.termux. Other apps can access this folder, unlike the data folder, and while it's likely intended for media files, nothing stops me from downloading files to it.
If you already have a large number of files in your external data folder, do note that there's no filesystem permissions issue with accessing the location; simply renaming the Android or data folder will allow access with a file manager.Just make sure you remember to rename it back before opening an app that needs it.
I am still running the Google-Play version of Termux. For backup and change to the F-Droid version I need some GBs of storage. Unfortunately, I don't have the /storage/XXXX-XXXX/Android/media/com.termux folder (XXXX-XXXX replaced with the actual value on my device). I am using Android 8.1 on that device. I cannot create this folder (permission denied). Probably I could create it as root but then the SELinux permissions will be wrong.
What can I do? Thanks for a hint, Helmut
@HJarausch Running command termux-setup-storage
automatically creates the "com.termux" folder on external storage volumes. You can also try to make it from Android file manager app.