Mick0311
Mick0311

Reputation: 181

Android: Determining connected USB device storage size

I have a widget that will tell the user the capacity of a connected USB device, as well as the amount of space used. I have gone through the android.hardware.usb API and I see nothing that can accomplish determining the size of a connected USB device and its usage.

Right now I am capturing Intent.ACTION_MEDIA_MOUNTED and searching in the Dir of the mount point for specific files etc... All of that is working fine, but for the life of me I cannot see how to leverage the API to determine the overall size, and usage, of a connected USB device.

Do any of you fine folks know, or have an article for me to read? Thanks all.

Upvotes: 0

Views: 442

Answers (1)

Chris Stratton
Chris Stratton

Reputation: 40397

It sounds like your device is actually mounting the connected USB device's file system, which seems like it may be a vendor add-on rather than a stock android capability.

If that is indeed the case, whatever other options you might have you can use the df shell command, or more properly duplicate its functionality in java or a native subroutine.

You can view the source of android's df here:

https://github.com/android/platform_system_core/blob/master/toolbox/df.c

It looks to be a fairly standard implementation - read /proc/mounts to find the filesystems, call statfs() on each one. You'd probably want to filter by those of interest.

Upvotes: 1

Related Questions