我怎样才能从USB闪存驱动器中读取数据? [英] How can I read data from a USB Flash Drive?

查看:447
本文介绍了我怎样才能从USB闪存驱动器中读取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发谷歌电视的应用程序,我想从USB闪存驱动器连接到谷歌电视读取图像,并显示在我的应用程序。我已经知道如何来显示图像,但我不知道如何从USB读取它。我试着用这个code:

I am developing an application for google tv and I would like to read an image from a USB Flash Drive connected to the google tv and show it in my application. I already know how to show the image but I dont know how to read it from the usb. I tried with this code:

File imgFile = new File("sdcard/image/1.jpg");

不过,这并不为USB工作。

But it doesn't work for the usb.

推荐答案

有没有公共API访问USB设备的文件系统。 getExternalStorageDirectory()是解决不了问题。

There is no public API to access the USB devices as a file system. getExternalStorageDirectory() is not the solution.

要解决这个不足,我建议看看 libmedia ,一个设计成一个工具箱库帮助开发人员构建应用程序。

To address this lack, I suggest to have a look at libmedia, a library designed as a toolbox to help developers to build applications.

就这么简单:

VolumeManager volumeManager = new VolumeManager();
List<Volume> volumes = volumeManager.getVolumes();
Volume volume = volumes.get(0);  // simplified
File rootFolder = volume.getRoot();
File imgFile = new File(rootFolder, "image/1.jpg");

这篇关于我怎样才能从USB闪存驱动器中读取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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