Udostępnij za pośrednictwem


Environment.ExternalStorageDirectory Property

Definition

Return the primary shared/external storage directory.

public static Java.IO.File? ExternalStorageDirectory { [Android.Runtime.Register("getExternalStorageDirectory", "()Ljava/io/File;", "")] get; }
[<get: Android.Runtime.Register("getExternalStorageDirectory", "()Ljava/io/File;", "")>]
static member ExternalStorageDirectory : Java.IO.File

Property Value

Attributes

Remarks

Return the primary shared/external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with #getExternalStorageState().

<em>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.</em>

On devices with multiple users (as described by UserManager), each user has their own isolated shared storage. Applications only have access to the shared storage for the user they're running as.

In devices with multiple shared/external storage directories, this directory represents the primary storage that the user will interact with. Access to secondary storage is available through Context#getExternalFilesDirs(String), Context#getExternalCacheDirs(), and Context#getExternalMediaDirs().

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 android.content.Context#getExternalFilesDir 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.

Writing to this path requires the android.Manifest.permission#WRITE_EXTERNAL_STORAGE permission, and starting in android.os.Build.VERSION_CODES#KITKAT, read access requires the android.Manifest.permission#READ_EXTERNAL_STORAGE permission, which is automatically granted if you hold the write permission.

Starting in android.os.Build.VERSION_CODES#KITKAT, if your application only needs to store internal data, consider using Context#getExternalFilesDir(String), Context#getExternalCacheDir(), or Context#getExternalMediaDirs(), which require no permissions to read or write.

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:

{

Java documentation for android.os.Environment.getExternalStorageDirectory().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also