Package com.github.mjdev.libaums
Class UsbMassStorageDevice
- java.lang.Object
-
- com.github.mjdev.libaums.UsbMassStorageDevice
-
public class UsbMassStorageDevice extends java.lang.ObjectClass representing a connected USB mass storage device. You can enumerate through all connected mass storage devices viagetMassStorageDevices(Context). This method only returns supported devices or if no device is connected an empty array.After choosing a device you have to get the permission for the underlying
UsbDevice. The underlyingUsbDevicecan be accessed viagetUsbDevice().After that you need to call
setupDevice(). This will initialize the mass storage device and read the partitions (Partition).The supported partitions can then be accessed via
getPartitions()and you can begin to read directories and files.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Releases theUsbInterfaceand closes theUsbDeviceConnection.BlockDeviceDrivergetBlockDevice()Returns the block device interface for this device.static UsbMassStorageDevice[]getMassStorageDevices(android.content.Context context)This method iterates through all connected USB devices and searches for mass storage devices.java.util.List<Partition>getPartitions()Returns the available partitions of the mass storage device.android.hardware.usb.UsbDevicegetUsbDevice()This returns theUsbDevicewhich can be used to request permission for communication.voidinit()Initializes the mass storage device and determines different things like for example the MBR or the file systems for the different partitions.
-
-
-
Method Detail
-
getMassStorageDevices
public static UsbMassStorageDevice[] getMassStorageDevices(android.content.Context context)
This method iterates through all connected USB devices and searches for mass storage devices.- Parameters:
context- Context to get theUsbManager- Returns:
- An array of suitable mass storage devices or an empty array if none could be found.
-
init
public void init() throws java.io.IOExceptionInitializes the mass storage device and determines different things like for example the MBR or the file systems for the different partitions.- Throws:
java.io.IOException- If reading from the physical device fails.java.lang.IllegalStateException- If permission to communicate with the underlyingUsbDeviceis missing.- See Also:
getUsbDevice()
-
close
public void close()
Releases theUsbInterfaceand closes theUsbDeviceConnection. After calling this method no further communication is possible. That means you can not read or write from or to the partitions returned bygetPartitions().
-
getPartitions
public java.util.List<Partition> getPartitions()
Returns the available partitions of the mass storage device. You have to callinit()before calling this method!- Returns:
- List of partitions.
-
getUsbDevice
public android.hardware.usb.UsbDevice getUsbDevice()
This returns theUsbDevicewhich can be used to request permission for communication.- Returns:
- Underlying
UsbDeviceused for communication.
-
getBlockDevice
public BlockDeviceDriver getBlockDevice()
Returns the block device interface for this device. Only use this if you know what you are doing, for a interacting (listing/reading/writing files) with a pen drive this is usually not needed- Returns:
- The BlockDeviceDriver implementation
-
-