次の方法で共有


Context.GetExternalFilesDir(String) Method

Definition

Returns the absolute path to the directory on the primary shared/external storage device 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 abstract Java.IO.File? GetExternalFilesDir (string? type);
[<Android.Runtime.Register("getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;", "GetGetExternalFilesDir_Ljava_lang_String_Handler")>]
abstract member 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 constants for a subdirectory: android.os.Environment#DIRECTORY_MUSIC, android.os.Environment#DIRECTORY_PODCASTS, android.os.Environment#DIRECTORY_RINGTONES, android.os.Environment#DIRECTORY_ALARMS, android.os.Environment#DIRECTORY_NOTIFICATIONS, android.os.Environment#DIRECTORY_PICTURES, or android.os.Environment#DIRECTORY_MOVIES.

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: <ul> <li>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). <li>There is no security enforced with these files. For example, any application holding android.Manifest.permission#WRITE_EXTERNAL_STORAGE can write to these files. </ul>

If a shared storage device is emulated (as determined by Environment#isExternalStorageEmulated(File)), it's 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.os.Build.VERSION_CODES#KITKAT, no permissions are required to read or write to the returned path; it's always accessible to the calling app. This only applies to paths generated for package name of the calling application. To access paths belonging to other packages, android.Manifest.permission#WRITE_EXTERNAL_STORAGE and/or android.Manifest.permission#READ_EXTERNAL_STORAGE are required.

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.

Here is an example of typical code to manipulate a file in an application's shared storage:

{

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

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