栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Android中访问USB大容量存储设备

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Android中访问USB大容量存储设备

在此示例中,我使用的是来自Apache的FileUtils,但是如果不使用它,您将看到用于读取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);        }    }}

In my manifest I have those lines, although I’m not sure they’re all
mandatory…

<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" />


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/446578.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号