Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you access external memory on Google TV

I'm developing using a Sony Internet TV as a development device, which has 4 USB ports. All or no ports can be used with external hard drives. How can I select and access external memory vs internal memory on the device.

I'm able to access the SD card, or at least what the TV labels as the SD card using the following:

Environment.getExternalStorageDirectory();

But I can't seem to figure out how to find external USB devices. I've attempted to go down the path of the UsbManager class, but it seems as though there should be an easier and more general way. I just want to be able to see mass storage devices and don't want to have to clean through vendor id's etc. But maybe I'm missing something there.

This should be possible as I'm looking for the same functionality found by the Media Player app when opening the menu and selecting "Select device".

I only need read access to the drives, but read/write could be useful.

Thanks in advance.

like image 391
dzimney Avatar asked Nov 13 '11 22:11

dzimney


2 Answers

In Google TV v2, there were some changes regarding USB storage support. The major changes for USB drives are:
1.USB drives will be mounted /mnt/media/usb.XXXXX instead of /sdcard. (XXXXX is decided by the ID(volume id : vfat or exfat, uuid : ntfs) of USB volume.)
2.GTV supports multiple USB drives. Users can plug multiple USB drives.

MediaProvider indexes all the media files in all the plugged USB volumes. So, applications can query against MediaProvider in order to retrieve all the media files.

Sample code:

Cursor cursor = getContentResolver().query(
Images.Media.EXTERNAL_CONTENT_URI,
new String[] {
Images.Media._ID,
Images.Media.DATA, // file path
},
null, null, null);

How can application detect when the drive has synced or ejected?:
You can register BroadcastReceiver in order to receive Intent.ACTION_MEDIA_SCANNER_FINISHED and Intent.ACTION_MEDIA_EJECT.

like image 128
Megha Joshi - GoogleTV DevRel Avatar answered Sep 21 '22 00:09

Megha Joshi - GoogleTV DevRel


So intuition says to use the USB accessories api. However, this is only avaible to android 3.1 and up and if I remember correctly, google tv adhers to the 3.0 API. That said, from the documentation:

com.android.future.usb: To support USB accessory mode in Android 2.3.4, the Google APIs add-on library includes the backported USB accessory APIs and they are contained in this namespace.

So checkout the Google APIs add-on library to access the usb stuff.

like image 35
Kurtis Nusbaum Avatar answered Sep 21 '22 00:09

Kurtis Nusbaum