Termux-app: Ability to use usb otg storage in termux

Created on 28 Mar 2016  路  9Comments  路  Source: termux/termux-app

Hi,

I am using Android 6 (cm13.0) and I have formatted my sd card as internal storage. I have already found https://termux.com/storage.html and when running termux-setup-storage I can acess my internal storage.

I also want to access a usb thumbdrive, which is visible in es explorer and the android storage settings, but will not be displayed beneath ~/storage (the folder external is missing as well).

Is this expected behaviour or is there something wrong on my device?

PS: the drive does show up in /storage btw. But trying to create a file on it will give a "permission denied"

enhancement

Most helpful comment

would this be of use:
https://github.com/magnusja/libaums

having access to a usb drive for backup or additional storage would be nice.

All 9 comments

I am on Android 5 and I can write to /storage/usbdisk without getting a "permission denied" error. Can you write to the usbdisk with other apps?

Yes, the behaviour changed in Android 6 a bit for external storage as far as i know. With the first Builds the drive could only be accessed from the storage settings, but starting with an update of es Explorer itmcould be opened directly as well.

@fornwall Is there anything that can be done here?

@Neo-Oli I'm not sure, need to test with a usb otg storage.

Perhaps direct file system access is not possible, and an api method could be added instead.

It seems that direct file system access is not possible starting from Android 6.0 - from Android USB media support documentation, as mentioned in this stackoverflow answer:

Multiple external storage devices
---------------------------------
Starting in Android 4.4, multiple external storage devices are surfaced to developers
through Context.getExternalFilesDirs(), Context.getExternalCacheDirs(),
and Context.getObbDirs().

External storage devices surfaced through these APIs must be a semi-permanent
part of the device (such as an SD card slot in a battery compartment).
Developers expect data stored in these locations to be available over long periods
of time. For this reason, transient storage devices (such as USB mass storage
drives) should not be surfaced through these APIs.

The WRITE_EXTERNAL_STORAGE permission must only grant write access to the
primary external storage on a device. Apps must not be allowed to write to
secondary external storage devices, except in their package-specific directories
as allowed by synthesized permissions. Restricting writes in this way ensures the
system can clean up files when applications are uninstalled.

USB media support
-------------------
Android 6.0 supports portable storage devices which are only connected to the
device for a short period of time, like USB flash drives. When a user inserts a new
portable device, the platform shows a notification to let them copy or manage the
contents of that device.

In Android 6.0, any device that is not adopted is considered portable. Because
portable storage is connected for only a short time, the platform avoids heavy
operations such as media scanning. Third-party apps must go through the
Storage Access Framework to interact with files on portable storage; direct
access is explicitly blocked for privacy and security reasons.

However, a command could be created (termux-storage-getfile) which requests a file from the system through a system file dialog (and perhaps outputs it to stdout, so it could be use either in pipes or like termux-storage-getfile > myfile.txt).

Also, it should be possible to write a termux-storage-putfile command, which takes a Termux-accessible file as argument, opens up a system file dialog where the user can choose a directory on storage devices where to put the file.

The termux-storage-getfile mechanism gives no way to preserve the original filename. Is it possible to implement something to preserve the filename?? For example, I call termux-storage-getfile without a destination filename, and the scripts creates a file with the same name of the file I select from the usb drive, and copies into it.

My thumb drive is mounted in /data/system/scsi/Disk1. It's owned by system, but I can read/write on it without error.
My android is 5.0.1

would this be of use:
https://github.com/magnusja/libaums

having access to a usb drive for backup or additional storage would be nice.

I need access to the OTG usb drive.

Was this page helpful?
0 / 5 - 0 ratings