Språk

ContextWrapper.GetExternalFilesDir(String) Method

Definition

Returns the absolute path to the directory on the primary external filesystem (that is somewhere on ExternalStorageDirectory) where the application can place persistent files it owns.

[Android.Runtime.Register("getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;", "GetGetExternalFilesDir_Ljava_lang_String_Handler")]
public override Java.IO.File? GetExternalFilesDir(string? type);
[<Android.Runtime.Register("getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;", "GetGetExternalFilesDir_Ljava_lang_String_Handler")>]
override this.GetExternalFilesDir : string -> Java.IO.File

Parameters

type
String

The type of files directory to return. May be null for the root of the files directory or one of the following Environment constants for a subdirectory: DirectoryMusic, DirectoryPodcasts, DirectoryRingtones, DirectoryAlarms, DirectoryNotifications, DirectoryPictures, or DirectoryMovies.

Returns

The absolute path to application-specific directory. May return null if shared storage is not currently available.

Attributes

Remarks

Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media. This is like getFilesDir() in that these files will be deleted when the application is uninstalled, however there are some important differences: Shared storage may not always be available, since removable media can be ejected by the user. Media state can be checked using Environment.getExternalStorageState(File) . Access by other apps depends on the Android version, the apps' target API levels, and the applicable storage permissions and restrictions. If a shared storage device is emulated (as determined by Environment.isExternalStorageEmulated(File) ), its contents are backed by a private user data partition, which means there is little benefit to storing data here instead of the private directories returned by getFilesDir() , etc. Starting in Android 4.4 (API level 19), no storage permission is required to read or write the calling app's path. The path may be unavailable or read-only. This only applies to paths generated for package name of the calling application. Access to paths belonging to other packages is subject to Android storage restrictions and may not be granted by storage permissions. 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. The returned path may change over time if different shared storage media is inserted, so only relative paths should be persisted. If you supply a non-null type to this function, the returned file will be a path to a sub-directory of the given type. Though these files are not automatically scanned by the media scanner, you can explicitly add them to the media database with MediaScannerConnection.scanFile . Note that this is not the same as Environment.getExternalStoragePublicDirectory() , which provides directories of media shared by all applications. The directories returned here are owned by the application, and their contents will be removed when the application is uninstalled. Unlike Environment.getExternalStoragePublicDirectory() , the directory returned here will be automatically created for you.

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.

Java documentation for android.content.ContextWrapper.getExternalFilesDir(java.lang.String).

Applies to