在這個例子中,我使用Apache的文件實用程序,但事件沒有它,你會看到用來讀取USB閃存驅動器的邏輯:
private UsbManager usbManager;
private UsbDevice clef;
ArrayList<File> images;
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
clef = null;
if (usbManager != null)
{
HashMap<String,UsbDevice> deviceList = usbManager.getDeviceList();
if (deviceList != null)
{
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while (deviceIterator.hasNext()) {
clef = deviceIterator.next();
}
}
}
if (clef != null)
{
File directory = new File("/storage/UsbDriveA/");
if (directory != null) {
if (directory.canRead()) {
images = new ArrayList<File>();
String[] imageExtensions = {"jpg","jpeg","png","gif","JPG","JPEG","PNG","GIF"};
Iterator<File> iterateImages = FileUtils.iterateFiles(directory, imageExtensions, true);
while (iterateImages.hasNext()) {
File theImage = iterateImages.next();
if (!theImage.getName().startsWith(".", 0))
images.add(theImage);
}
// custom process/methods... not very relevant here :
imageIndex = 0;
scale = 1.0f;
countImgs = images.size();
loadImage(imageIndex);
}
}
}
在我的清單我有那些線,雖然我米不知道他們都是強制性的...
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
來源
2015-02-21 23:02:23
JBA
哇什麼手機,有一個USB端口?? – DnR
哈哈我會用我正在使用的電纜圖片更新我的問題。 – Tiwaz89
啊,我明白了。我認爲手機上有一個_Female_ USB端口,可直接插入電纜而不需要電纜-_- – DnR