public class Environment extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Environment.UserEnvironment |
Modifier and Type | Field and Description |
---|---|
static String |
DIRECTORY_ALARMS
Standard directory in which to place any audio files that should be
in the list of alarms that the user can select (not as regular
music).
|
static String |
DIRECTORY_ANDROID |
static String |
DIRECTORY_DCIM
The traditional location for pictures and videos when mounting the
device as a camera.
|
static String |
DIRECTORY_DOWNLOADS
Standard directory in which to place files that have been downloaded by
the user.
|
static String |
DIRECTORY_MOVIES
Standard directory in which to place movies that are available to
the user.
|
static String |
DIRECTORY_MUSIC
Standard directory in which to place any audio files that should be
in the regular list of music for the user.
|
static String |
DIRECTORY_NOTIFICATIONS
Standard directory in which to place any audio files that should be
in the list of notifications that the user can select (not as regular
music).
|
static String |
DIRECTORY_PICTURES
Standard directory in which to place pictures that are available to
the user.
|
static String |
DIRECTORY_PODCASTS
Standard directory in which to place any audio files that should be
in the list of podcasts that the user can select (not as regular
music).
|
static String |
DIRECTORY_RINGTONES
Standard directory in which to place any audio files that should be
in the list of ringtones that the user can select (not as regular
music).
|
static String |
MEDIA_BAD_REMOVAL
getExternalStorageState() returns MEDIA_BAD_REMOVAL if the media was
removed before it was unmounted. |
static String |
MEDIA_CHECKING
getExternalStorageState() returns MEDIA_CHECKING if the media is present
and being disk-checked |
static String |
MEDIA_MOUNTED
getExternalStorageState() returns MEDIA_MOUNTED if the media is present
and mounted at its mount point with read/write access. |
static String |
MEDIA_MOUNTED_READ_ONLY
getExternalStorageState() returns MEDIA_MOUNTED_READ_ONLY if the media is present
and mounted at its mount point with read only access. |
static String |
MEDIA_NOFS
getExternalStorageState() returns MEDIA_NOFS if the media is present
but is blank or is using an unsupported filesystem |
static String |
MEDIA_REMOVED
getExternalStorageState() returns MEDIA_REMOVED if the media is not present. |
static String |
MEDIA_SHARED
getExternalStorageState() returns MEDIA_SHARED if the media is present
not mounted, and shared via USB mass storage. |
static String |
MEDIA_UNMOUNTABLE
getExternalStorageState() returns MEDIA_UNMOUNTABLE if the media is present
but cannot be mounted. |
static String |
MEDIA_UNMOUNTED
getExternalStorageState() returns MEDIA_UNMOUNTED if the media is present
but not mounted. |
Constructor and Description |
---|
Environment() |
Modifier and Type | Method and Description |
---|---|
static File |
getDataDirectory()
Gets the Android data directory.
|
static File |
getDownloadCacheDirectory()
Gets the Android download/cache content directory.
|
static File |
getEmulatedStorageObbSource() |
static File |
getEmulatedStorageSource(int userId) |
static File |
getExternalStorageAndroidDataDir()
Returns the path for android-specific data on the SD card.
|
static File |
getExternalStorageAppCacheDirectory(String packageName)
Generates the path to an application's cache.
|
static File |
getExternalStorageAppDataDirectory(String packageName)
Generates the raw path to an application's data
|
static File |
getExternalStorageAppFilesDirectory(String packageName)
Generates the path to an application's files.
|
static File |
getExternalStorageAppMediaDirectory(String packageName)
Generates the raw path to an application's media
|
static File |
getExternalStorageAppObbDirectory(String packageName)
Generates the raw path to an application's OBB files
|
static File |
getExternalStorageDirectory()
Gets the Android external storage directory.
|
static File |
getExternalStoragePublicDirectory(String type)
Get a top-level public external storage directory for placing files of
a particular type.
|
static String |
getExternalStorageState()
Gets the current state of the primary "external" storage device.
|
static File |
getLegacyExternalStorageDirectory() |
static File |
getLegacyExternalStorageObbDirectory() |
static File |
getMediaStorageDirectory()
Return directory used for internal media storage, which is protected by
android.Manifest.permission#WRITE_MEDIA_STORAGE . |
static File |
getRootDirectory()
Gets the Android root directory.
|
static File |
getSecureDataDirectory()
Gets the data directory for secure storage.
|
static File |
getSystemSecureDirectory()
Gets the system directory available for secure storage.
|
static File |
getUserSystemDirectory(int userId)
Return the system directory for a user.
|
static void |
initForCurrentUser() |
static boolean |
isEncryptedFilesystemEnabled()
Returns whether the Encrypted File System feature is enabled on the device or not.
|
static boolean |
isExternalStorageEmulated()
Returns whether the device has an external storage device which is
emulated.
|
static boolean |
isExternalStorageRemovable()
Returns whether the primary "external" storage device is removable.
|
public static String DIRECTORY_ANDROID
public static String DIRECTORY_MUSIC
DIRECTORY_PODCASTS
, DIRECTORY_NOTIFICATIONS
,
DIRECTORY_ALARMS
, and DIRECTORY_RINGTONES
as a series
of directories to categories a particular audio file as more than one
type.public static String DIRECTORY_PODCASTS
DIRECTORY_MUSIC
,
DIRECTORY_NOTIFICATIONS
,
DIRECTORY_ALARMS
, and DIRECTORY_RINGTONES
as a series
of directories to categories a particular audio file as more than one
type.public static String DIRECTORY_RINGTONES
DIRECTORY_MUSIC
,
DIRECTORY_PODCASTS
, DIRECTORY_NOTIFICATIONS
, and
DIRECTORY_ALARMS
as a series
of directories to categories a particular audio file as more than one
type.public static String DIRECTORY_ALARMS
DIRECTORY_MUSIC
,
DIRECTORY_PODCASTS
, DIRECTORY_NOTIFICATIONS
,
and DIRECTORY_RINGTONES
as a series
of directories to categories a particular audio file as more than one
type.public static String DIRECTORY_NOTIFICATIONS
DIRECTORY_MUSIC
,
DIRECTORY_PODCASTS
,
DIRECTORY_ALARMS
, and DIRECTORY_RINGTONES
as a series
of directories to categories a particular audio file as more than one
type.public static String DIRECTORY_PICTURES
public static String DIRECTORY_MOVIES
public static String DIRECTORY_DOWNLOADS
public static String DIRECTORY_DCIM
public static final String MEDIA_REMOVED
getExternalStorageState()
returns MEDIA_REMOVED if the media is not present.public static final String MEDIA_UNMOUNTED
getExternalStorageState()
returns MEDIA_UNMOUNTED if the media is present
but not mounted.public static final String MEDIA_CHECKING
getExternalStorageState()
returns MEDIA_CHECKING if the media is present
and being disk-checkedpublic static final String MEDIA_NOFS
getExternalStorageState()
returns MEDIA_NOFS if the media is present
but is blank or is using an unsupported filesystempublic static final String MEDIA_MOUNTED
getExternalStorageState()
returns MEDIA_MOUNTED if the media is present
and mounted at its mount point with read/write access.public static final String MEDIA_MOUNTED_READ_ONLY
getExternalStorageState()
returns MEDIA_MOUNTED_READ_ONLY if the media is present
and mounted at its mount point with read only access.public static final String MEDIA_SHARED
getExternalStorageState()
returns MEDIA_SHARED if the media is present
not mounted, and shared via USB mass storage.public static final String MEDIA_BAD_REMOVAL
getExternalStorageState()
returns MEDIA_BAD_REMOVAL if the media was
removed before it was unmounted.public static final String MEDIA_UNMOUNTABLE
getExternalStorageState()
returns MEDIA_UNMOUNTABLE if the media is present
but cannot be mounted. Typically this happens if the file system on the
media is corrupted.public static void initForCurrentUser()
public static File getRootDirectory()
public static File getSystemSecureDirectory()
public static File getSecureDataDirectory()
public static File getMediaStorageDirectory()
android.Manifest.permission#WRITE_MEDIA_STORAGE
.public static File getUserSystemDirectory(int userId)
public static boolean isEncryptedFilesystemEnabled()
true
if Encrypted File System feature is enabled, false
if disabled.public static File getDataDirectory()
public static File getExternalStorageDirectory()
getExternalStorageState()
.
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
On devices with multiple users (as described by UserManager
),
each user has their own isolated external storage. Applications only
have access to the external storage for the user they're running as.
In devices with multiple "external" storage directories (such as both secure app storage and mountable shared storage), this directory represents the "primary" external storage that the user will interact with.
Applications should not directly use this top-level directory, in
order to avoid polluting the user's root namespace. Any files that are
private to the application should be placed in a directory returned
by Context.getExternalFilesDir
, which the system will take care of deleting
if the application is uninstalled. Other shared files should be placed
in one of the directories returned by
getExternalStoragePublicDirectory(java.lang.String)
.
Writing to this path requires the
android.Manifest.permission#WRITE_EXTERNAL_STORAGE
permission. In
a future platform release, access to this path will require the
android.Manifest.permission#READ_EXTERNAL_STORAGE
permission,
which is automatically granted if you hold the write permission.
This path may change between platform versions, so applications should only persist relative paths.
Here is an example of typical code to monitor the state of external storage:
public static File getLegacyExternalStorageDirectory()
public static File getLegacyExternalStorageObbDirectory()
public static File getEmulatedStorageSource(int userId)
public static File getEmulatedStorageObbSource()
public static File getExternalStoragePublicDirectory(String type)
On devices with multiple users (as described by UserManager
),
each user has their own isolated external storage. Applications only
have access to the external storage for the user they're running as.
Here is an example of typical code to manipulate a picture on the public external storage:
type
- The type of storage directory to return. Should be one of
DIRECTORY_MUSIC
, DIRECTORY_PODCASTS
,
DIRECTORY_RINGTONES
, DIRECTORY_ALARMS
,
DIRECTORY_NOTIFICATIONS
, DIRECTORY_PICTURES
,
DIRECTORY_MOVIES
, DIRECTORY_DOWNLOADS
, or
DIRECTORY_DCIM
. May not be null.File.mkdirs()
.public static File getExternalStorageAndroidDataDir()
public static File getExternalStorageAppDataDirectory(String packageName)
public static File getExternalStorageAppMediaDirectory(String packageName)
public static File getExternalStorageAppObbDirectory(String packageName)
public static File getExternalStorageAppFilesDirectory(String packageName)
public static File getExternalStorageAppCacheDirectory(String packageName)
public static File getDownloadCacheDirectory()
public static String getExternalStorageState()
getExternalStorageDirectory()
public static boolean isExternalStorageRemovable()
See getExternalStorageDirectory()
for more information.
public static boolean isExternalStorageEmulated()
getExternalStorageDirectory()
will be allocated using a portion of
the internal storage system.
Certain system services, such as the package manager, use this to determine where to install an application.
Emulated external storage may also be encrypted - see
DevicePolicyManager.setStorageEncryption(
android.content.ComponentName, boolean)
for additional details.