How to access external storage on Google TV

I am developing using Sony Internet TV as a development device having 4 USB ports. All or no ports can be used with external hard drives. How can I select and access external memory and internal memory on a device.

I can access the SD card or at least that the TV stickers as an SD card using the following:

Environment.getExternalStorageDirectory(); 

But I can’t figure out how to find external USB devices. I tried to follow the path of the UsbManager class, but it seems that there should be a simpler and more general way. I just want to see mass storage devices and don't want to clean them through a vendor identifier, etc. But maybe I don’t see something there.

This should be possible, since I'm looking for the same functionality that Media Player found when I opened the menu and selected "Select device."

I only need read access to the disks, but read / write can be useful.

Thanks in advance.

+6
source share
4 answers

Google TV v2 has undergone some changes regarding support for USB drives. Key changes for USB drives:
1.USB drives will be installed /mnt/media/usb.XXXXX instead of / sdcard. (XXXXX is identified by the identifier (volume id: vfat or exfat, uuid: ntfs) of the USB volume.)
2.GTV supports multiple USB drives. Users can connect multiple USB drives.

MediaProvider indexes all media files on all connected USB volumes. Thus, applications can request MediaProvider to receive all media files.

Code example:

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

How can an application detect when a drive is synchronized or ejected? You can register BroadcastReceiver to receive Intent.ACTION_MEDIA_SCANNER_FINISHED and Intent.ACTION_MEDIA_EJECT.

+6
source

So, intuition says to use api USB accessories . However, it is only available for Android version 3.1 and higher, and if I remember correctly, Google Tv Aders to API 3.0. However, from the documentation:

com.android.future.usb: to support the USB accessory mode in Android 2.3.4, the Google API add-on library includes auxiliary APIs with an external interface and they are contained in this namespace.

So check out the google API additional library for access to usb content.

+1
source

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

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

+1
source

You cannot access USB devices with any getExternalXXX() , and by going through MediaProvider you will have a flat collection (the directory structure is lost) of only files classified as media (for example, no .txt).

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

Code example:

 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(); } } 
0
source

Source: https://habr.com/ru/post/901400/


All Articles