StorageVolume
public
final
class
StorageVolume
extends Object
implements
Parcelable
| java.lang.Object | |
| ↳ | android.os.storage.StorageVolume |
Information about a shared/external storage volume for a specific user.
A device always has one (and one only) primary storage volume, but it could have extra volumes, like SD cards and USB drives. This object represents the logical view of a storage volume for a specific user: different users might have different views for the same physical volume (for example, if the volume is a built-in emulated storage).
The storage volume is not necessarily mounted, applications should use getState() to
verify its state.
Applications willing to read or write to this storage volume needs to get a permission from the user first, which can be achieved in the following ways:
- To get access to standard directories (like the
DIRECTORY_PICTURES), they can use thecreateAccessIntent(String). This is the recommend way, since it provides a simpler API and narrows the access to the given directory (and its descendants). - To get access to any directory (and its descendants), they can use the Storage Acess
Framework APIs (such as
ACTION_OPEN_DOCUMENTandACTION_OPEN_DOCUMENT_TREE, although these APIs do not guarantee the user will select this specific volume. - To get read and write access to the primary storage volume, applications can declare the
READ_EXTERNAL_STORAGEandWRITE_EXTERNAL_STORAGEpermissions respectively, with the latter including the former. This approach is discouraged, since users may be hesitant to grant broad access to all files contained on a storage device.
It can be obtained through getStorageVolumes() and
getPrimaryStorageVolume() and also as an extra in some broadcasts
(see EXTRA_STORAGE_VOLUME).
See getExternalStorageDirectory() for more info about shared/external
storage semantics.
Summary
Constants | |
|---|---|
String |
EXTRA_STORAGE_VOLUME
Name of the |
Inherited constants |
|---|
android.os.Parcelable
|
Fields | |
|---|---|
public
static
final
Creator<StorageVolume> |
CREATOR
|
Public methods | |
|---|---|
Intent
|
createAccessIntent(String directoryName)
Builds an intent to give access to a standard storage directory or entire volume after obtaining the user's approval. |
int
|
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one. |
String
|
getDescription(Context context)
Returns a user-visible description of the volume. |
String
|
getState()
Returns the current state of the volume. |
String
|
getUuid()
Gets the volume UUID, if any. |
int
|
hashCode()
Returns a hash code value for the object. |
boolean
|
isEmulated()
Returns true if the volume is emulated. |
boolean
|
isPrimary()
Returns true if the volume is the primary shared/external storage, which is the volume
backed by |
boolean
|
isRemovable()
Returns true if the volume is removable. |
String
|
toString()
Returns a string representation of the object. |
void
|
writeToParcel(Parcel parcel, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
|---|---|
java.lang.Object
| |
android.os.Parcelable
| |
Constants
EXTRA_STORAGE_VOLUME
String EXTRA_STORAGE_VOLUME
Name of the Parcelable extra in the ACTION_MEDIA_REMOVED,
ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_CHECKING,
ACTION_MEDIA_NOFS, ACTION_MEDIA_MOUNTED,
ACTION_MEDIA_SHARED, ACTION_MEDIA_BAD_REMOVAL,
ACTION_MEDIA_UNMOUNTABLE, and ACTION_MEDIA_EJECT broadcast that
contains a StorageVolume.
Constant Value: "android.os.storage.extra.STORAGE_VOLUME"
Fields
Public methods
createAccessIntent
Intent createAccessIntent (String directoryName)
Builds an intent to give access to a standard storage directory or entire volume after obtaining the user's approval.
When invoked, the system will ask the user to grant access to the requested directory (and
its descendants). The result of the request will be returned to the activity through the
onActivityResult method.
To gain access to descendants (child, grandchild, etc) documents, use
buildDocumentUriUsingTree(Uri, String), or
buildChildDocumentsUriUsingTree(Uri, String) with the returned URI.
If your application only needs to store internal data, consider using
Context.getExternalFilesDirs,
getExternalCacheDirs(), or getExternalMediaDirs(), which
require no permissions to read or write.
Access to the entire volume is only available for non-primary volumes (for the primary
volume, apps can use the READ_EXTERNAL_STORAGE and
WRITE_EXTERNAL_STORAGE permissions) and should be used
with caution, since users are more likely to deny access when asked for entire volume access
rather than specific directories.
| Parameters | |
|---|---|
directoryName |
String:
must be one of DIRECTORY_MUSIC,
DIRECTORY_PODCASTS, DIRECTORY_RINGTONES,
DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS,
DIRECTORY_PICTURES, DIRECTORY_MOVIES,
DIRECTORY_DOWNLOADS, DIRECTORY_DCIM, or
DIRECTORY_DOCUMENTS, or {code null} to request access to the
entire volume. |
| Returns | |
|---|---|
Intent |
intent to request access, or null if the requested directory is invalid for
that volume. |
See also:
describeContents
int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(Parcel, int),
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR bit.
| Returns | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
equals
boolean equals (Object obj)
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation
on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, this method returns true if and only
if x and y refer to the same object
(x == y has the value true).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode method, which states
that equal objects must have equal hash codes.
| Parameters | |
|---|---|
obj |
Object:
the reference object with which to compare. |
| Returns | |
|---|---|
boolean |
true if this object is the same as the obj
argument; false otherwise. |
getDescription
String getDescription (Context context)
Returns a user-visible description of the volume.
| Parameters | |
|---|---|
context |
Context
|
| Returns | |
|---|---|
String |
the volume description |
getState
String getState ()
Returns the current state of the volume.
| Returns | |
|---|---|
String |
one of MEDIA_UNKNOWN, MEDIA_REMOVED,
MEDIA_UNMOUNTED, MEDIA_CHECKING,
MEDIA_NOFS, MEDIA_MOUNTED,
MEDIA_MOUNTED_READ_ONLY, MEDIA_SHARED,
MEDIA_BAD_REMOVAL, or MEDIA_UNMOUNTABLE.
|
hashCode
int hashCode ()
Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap.
The general contract of hashCode is:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
equals(java.lang.Object)method, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
JavaTM programming language.)
| Returns | |
|---|---|
int |
a hash code value for this object. |
isEmulated
boolean isEmulated ()
Returns true if the volume is emulated.
| Returns | |
|---|---|
boolean |
is removable |
isPrimary
boolean isPrimary ()
Returns true if the volume is the primary shared/external storage, which is the volume
backed by getExternalStorageDirectory().
| Returns | |
|---|---|
boolean |
|
isRemovable
boolean isRemovable ()
Returns true if the volume is removable.
| Returns | |
|---|---|
boolean |
is removable |
toString
String toString ()
Returns a string representation of the object. In general, the
toString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| Returns | |
|---|---|
String |
a string representation of the object. |
writeToParcel
void writeToParcel (Parcel parcel, int flags)
Flatten this object in to a Parcel.
| Parameters | |
|---|---|
parcel |
Parcel:
The Parcel in which the object should be written. |
flags |
int:
Additional flags about how the object should be written.
May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
|


