termux / termux-api

Termux add-on app which exposes device functionality as API to command line programs.
https://f-droid.org/en/packages/com.termux.api/
2.23k stars 446 forks source link

Rudimentary tools to write to the external sd card #37

Open Neo-Oli opened 8 years ago

Neo-Oli commented 8 years ago

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.

SDRausty commented 6 years ago

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.

innolee commented 3 years ago

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.

Efreak commented 3 years ago

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

SDRausty commented 3 years ago

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?

ghost commented 3 years ago

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

SDRausty commented 3 years ago

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](https://github.com/shlibs/shlibs.bash/commit/368a8a3cf5236c545ded0ba1ff0c210616db0535#diff-1899d25d36c5fdd9d9f8092f0ff88be8d5c719c257caa2d86682651955cfd15fR7)

HJarausch commented 3 years ago

@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

ghost commented 3 years ago

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