Android list files from USB Drive
Asked Answered
O

1

1

I currently have a working implementation that allows me to list USB devices, request permission for that USB device and then connect to them (mainly from http://developer.android.com/guide/topics/connectivity/usb/host.html). The code I have is the same as the linked article but none of the methods on the classes provided are for listing files on the device or checking if files exist.

However I do not understand how I can list files that are on the USB device to check if files exists before transferring data.

The device "path" is along the lines of /dev/bus/usb/00x but this can't be accessed directly through File. I see the app ES File Explorer is able to list files on a USB (non-rooted device) so I know it is possible. I have also tried accessing URI paths like usb://100x as it seemed like ES File Explorer was doing that, but I had no luck.

I have tried using the Storage Access Framework. On a Samsung Galaxy Tab it works with both SD Cards and USBs, however on the Google Nexus 10 it does not work with either (it has no SD Card slot) so I'm trying to implement another way to talk to the USB.

Version is Lollipop and above.

Any ideas? Thanks.

Ottava answered 14/1, 2016 at 17:12 Comment(5)
Which Android version?Waxen
Edited question with a bit more detail as it might be a tablet issue... but it's Lollipop (5.x)Ottava
Under Lollipop a usb stick is as far as i know always reachable in a folder like /mnt/usbdrive, /storage/0/usbdrive and so on. Why not use that?Waxen
@Waxen When I list what's in storage there's nothing but emulated and legacy (both pointing to same place). In /mnt there's no folder/file I can see that represents the USB Drive, just other things that are mostly empty.Ottava
When you use Storage Access Framewor what part doesn't work?Cushman
D
0

Please refer this link. Every mass storage device has at least one interface descriptor with the class code 08h, which stands for the mass storage class. The mass storage class is not defined in the device descriptor! The USB interface has exactly two endpoint descriptors. One IN endpoint to read from the device and one OUT endpoint to write to the device2. Reading and writing in this case does not necessarily mean reading or writing on the actual storage medium, this is described later. There are two different types regarding the mass storage class. There is the bulk-only transport (BBB) mechanism which is the most common one. All newer devices follow that standard. Then there is the Control/Bulk/Interrupt (CBI) standard which is no longer important, because the USB-IF recommends using the BBB approach

UsbDevice is recognized as massStorage Device If:

usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_MASS_STORAGE
                        || usbInterface.getInterfaceSubclass() == INTERFACE_SUBCLASS // int 6
                        || usbInterface.getInterfaceProtocol() == INTERFACE_PROTOCOL // int 80

and

usbInterface.getEndpointCount() == 2

where one of endpoint must satisfy following:

endPoint direction == 0
endPoint type = UsbConstants.USB_ENDPOINT_XFER_BULK //int 2
Donal answered 23/2, 2017 at 4:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.