public class VolumeManager extends Object
The purpose of a volume manager is to access the Media Storage Directory of an Android device,
as any other part of the file system. For each plugged-in USB device, you get
a Volume
object.
When developing on a device without any USB connector or with a fewer number
of connectors than the expected target, you can fake one or more existing ordinary internal directory
as an additional Media Storage Directory containing emulated USB devices,
with addMediaStorageDirectory()
.
In that directory, normal files are ignored but each directory simulates a mount point for a volume.
Optionally, these emulated volumes can be given a label with a special convention:
store the label as a UTF-8 string in a file named .label
located at the volume root.
If this file is not present or if its contents is empty, the label defaults to the root folder name.
Examples
Here is a possible tree for one emulated Media Storage Directory having two USB devices:
/mnt/sdcard//Movies/ |_ usb.0000-0001/ | |_ .label | |_ myVideo.mp4 |_ usb.E9D9-4932/ |_ myOtherVideo.mp4
Here is a partial sample of usage in an application:
VolumeManager volumeManager = new VolumeManager(); volumeManager.addMediaStorageDirectory("/mnt/sdcard/Movies"); List<Volume> volumes = volumeManager.getVolumes(); for (Volume v: volumes) { Log.d(TAG, "volume label: " + v.getLabel()); }Suppose there is an USB stick labeled
Android
and that the .label
file contains MyLabel
,
here is the potential output:
volume label: Android volume label: MyLabel volume label: usb.E9D9-4932
Constructor and Description |
---|
VolumeManager()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addMediaStorageDirectory(File directory)
Adds an emulated Media Storage Directory where looking for volumes.
|
boolean |
addMediaStorageDirectory(String pathname)
Adds an emulated Media Storage Directory where looking for volumes.
|
List<Volume> |
getVolumes()
Returns the list of currently mounted volumes.
|
public boolean addMediaStorageDirectory(String pathname)
pathname
- The pathname to a directory hosting emulated volumes.true
if the pathname designates an existing file and this file is a directory.public boolean addMediaStorageDirectory(File directory)
directory
- The directory hosting emulated volumes.true
if the argument designates an existing file and this file is a directory.