How to read data from a USB drive?

I am developing an application for google tv and I would like to read the image from a USB flash drive connected to Google TV and show it in my application. I already know how to display an image, but I do not know how to read it from USB. I tried with this code:

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

But this does not work for usb.

+5
source share
2 answers

I think you need to use:

"/ sdCard / ...." instead of "sdcard / ..."

If you try "sdcard / ..", it will be read from the file directory of your application, not the SDCard you want. Therefore, in your case, it will try to open "/data/data/your_project_package_structure/files/sdcard/image/1.jpg"

, /usb

Uri u = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "blabla.xml"));

, .

+1

API USB- . getExternalStorageDirectory() .

, libmedia - , , .

, :

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

All Articles