5

I am trying to use the android host api for USB storage. I have many doubts regarding same.

  1. What all things are possible using host api. I want to see the content of USB and if possible so the normal file operation. I didnt find any documentation help regarding this.

  2. I am able to claimInterface using UsbDeviceConnection class API but I'm unable to understand how the bulkTransfer works so if anyone can guide me or give some reference I will try myself.

I tried reading the USB specification also, I understood how bulkTransfer works at USB level but unable to relate how android/java file operations are possible using bulkTransfer which using UsbEndpoint not the File Descriptor.

Thanks in Advance !!

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
Brijesh Masrani
  • 1,439
  • 3
  • 16
  • 27

1 Answers1

5

The Android USB Host APIs do not include USB Mass Storage filesystem code, nor as of this writing in 2014 will "stock" Android mount a USB Mass Storage volume at operating system level.

To access a USB Mass Storage device using the stock Android USB Host APIs, you must therefore implement in your Application code both the necessary raw-USB operations to achieve block-level device access, and the appropriate filesystem logic itself. Needless to say, the details of such are of a complexity beyond the scope of an answer here, but you could start by studying documentation or existing implementations of USB Mass Storage drivers and filesystem drivers for other platforms.


It appears the situation in Android 6 may be different, and access via the USB host apis to something that version recognizes as a storage device might even no longer be permitted. Those targeting Android 6+ may need to look elsewhere, but older devices will remain in use for some time.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • OK understood. is it possible to display the content of USB storage? – Brijesh Masrani Oct 10 '14 at 06:15
  • And if file transfer is not possible what is use case for bulk transfer api? As per my understanding control transfer is for joystick kind of device.correct me if I'm wrong. – Brijesh Masrani Oct 10 '14 at 07:23
  • 2
    Displaying contents is a form of file system access and requires everything I listed in at least some degree. Bulk Transfer is a generic method for moving non-trivial amounts of data. Remember there are a huge variety of USB peripherals for an almost unimaginable range of purposes. Andrioid supports their generic underpinnings. But their specifics are left for you to implement. – Chris Stratton Oct 10 '14 at 13:17
  • @ChrisStratton since Android 6 USB OTG is handled by `vold` provided that it has a supported filesystem (FAT[N] or now exFAT too). For other filesystems like NTFS (and even for FAT and exFAT), USB host mass storage still works e.g. [Paragon's](https://play.google.com/store/apps/details?id=com.paragon.tcplugins_ntfs_ro) and [libaums](https://github.com/magnusja/libaums). Right? But I think no one has tried so far to stack `ext4` over mass storage over USB host APIs. – Irfan Latif Jan 02 '20 at 11:44