Android列出USB驱动器中的文件 [英] Android list files from USB Drive
问题描述
我目前有一个有效的实现方式,该功能允许我列出USB设备,请求该USB设备的权限,然后连接到它们(主要来自/dev/bus/usb/00x行,但是不能直接通过File
访问.我看到应用程序ES File Explorer
能够列出USB(非根设备)上的文件,因此我知道这是可能的.我还尝试过访问usb://100x
之类的URI路径,好像ES File Explorer那样,但是我没有运气.
我尝试使用存储访问框架.在Samsung Galaxy Tab上,它可同时与SD卡和USB一起使用,但是在Google Nexus 10上,它既不能与SD卡一起使用(它没有SD卡插槽),因此我正在尝试实现另一种与USB通讯的方式./p>
版本是棒棒糖及更高版本.
有什么想法吗?谢谢.
请参考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.
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
这篇关于Android列出USB驱动器中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!