termux-api icon indicating copy to clipboard operation
termux-api copied to clipboard

Rudimentary tools to write to the external sd card

Open Neo-Oli opened this issue 8 years ago • 8 comments

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.

Neo-Oli avatar Aug 15 '16 06:08 Neo-Oli

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 avatar Feb 17 '21 15:02 innolee

@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.

Efreak avatar Apr 24 '21 03:04 Efreak

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"

Ref Reddit: Android 11 (with Termux storage permission denied) question; What's the source for the shortcut to the file manager of the settings app?

SDRausty avatar Apr 24 '21 13:04 SDRausty

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).

ghost avatar Apr 24 '21 20:04 ghost

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?

if [ ! -e /storage/emulated/0/Android/media/com.termux/builtAPKs ] # if directory does not exist then # create directory mkdir -p /storage/emulated/0/Android/media/com.termux/builtAPKs || printf "\\e[1;1;38;5;124m%s\\e[1;1;38;5;122m%s\\e[1;32m%s\\e[0m\\n" "Could not create directory Android/media/com.termux/builtAPKs to deposit APK files. " "Please create this directory in Android" ": Continuing..." fi

SDRausty avatar Apr 25 '21 02:04 SDRausty

@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 avatar Apr 27 '21 19:04 HJarausch

@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.

ghost avatar Apr 27 '21 19:04 ghost