Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read data from a USB Flash Drive?

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");

But it doesn't work for the usb.

like image 345
user1286765 Avatar asked Nov 05 '22 03:11

user1286765


1 Answers

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

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

As simple as:

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");
like image 73
libeasy Avatar answered Nov 09 '22 08:11

libeasy