Android列出USB驱动器中的文件 [英] Android list files from USB Drive

查看:137
本文介绍了Android列出USB驱动器中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个有效的实现方式,该功能允许我列出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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆