How can you access external memory on Google TV
Asked Answered
D

4

6

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.

Din answered 13/11, 2011 at 22:37 Comment(0)
W
6

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.

Wulfe answered 14/11, 2011 at 6:13 Comment(4)
Is /mnt/media/usb.XXXXX something we as SDK developers can rely upon? I'm not aware that this is documented anywhere else. IOW, is this the sort of thing that, say, book authors should be perhaps including in books covering Google TV? :-) Thanks!Norvell
I will find out and let you know in a couple days.Wulfe
There are no plans for USB storage APIs as of now. The recommended way for accessing USB storage is through MediaProvider.Wulfe
I thought maybe that might be the case. Thanks for the clarification!Norvell
P
1

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.

Pharmacopsychosis answered 13/11, 2011 at 22:41 Comment(1)
Actually, they're shipping with 3.1. I'll look into the USB accesories api. Thank you.Din
N
1

But I can't seem to figure out how to find external USB devices.

There is no official support in the Android SDK for external USB drives. I see nothing in the Google TV developer documentation to suggest that they have added anything in this area.

Norvell answered 13/11, 2011 at 23:5 Comment(3)
Does the USB accessories api not work with external usb devices?Pharmacopsychosis
@KurtisNusbaum: Well, you can't, for example, implement USB Mass Storage Mode in Java. Quoting the page you linked to: "USB accessory mode allows users to connect USB host hardware specifically designed for Android-powered devices. The accessories must adhere to the Android accessory protocol outlined in the Android Accessory Development Kit documentation." This isn't USB Mass Storage Mode. Plugging in a USB drive should auto-mount it, but there's no official API to find the mount points, determine whether it's writeable, etc.Norvell
It appears that mass storage devices are not "Accessories" but "Devices". I'm still working through the problem and have yet to be able to recognize a device (programmatically) as a mass storage device. Currently I'm able to view a list of devices, but my usb mass storage devices do not return UsbConstants. USB_CLASS_MASS_STORAGE link[/link] as their device class (using Device.getDeviceClass). Maybe Google hasn't fully flushed out the usb package.Din
V
0

You can't access the usb devices with any getExternalXXX(), and by going through MediaProvider you will have a flat collection (the directory structure is lost) of the only files classified as media (e.g. no .txt).

I developed libmedia for this need and some others. Tested on a Sony NSZ-GS7.

Sample code:

VolumeManager volumeManager = new VolumeManager();
List<Volume> volumes = volumeManager.getVolumes();
for (Volume volume: volumes) {
    String label = volume.getLabel();
    File rootFolder = volume.getRoot();
    File[] files = rootFolder.listFiles();
    for (File file: files) {
        String filename = file.getName();
    }
}
Vying answered 6/3, 2013 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.