android的Environment类
在没有挂载前存储媒体已经被移除。 |
||
正在检查存储媒体。 |
||
存储媒体已经挂载,并且挂载点可读/写。 |
||
存储媒体已经挂载,挂载点只读。 |
||
存储媒体是空白或是不支持的文件系统。 |
||
存储媒体被移除。 |
||
存储媒体正在通过USB共享。 |
||
存储媒体无法挂载。 |
||
存储媒体没有挂载。 |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public static String |
系统提醒铃声存放的标准目录。 |
||||||||||
public static String |
相机拍摄照片和视频的标准目录。 |
||||||||||
public static String |
下载的标准目录。 |
||||||||||
public static String |
电影存放的标准目录。 |
||||||||||
public static String |
音乐存放的标准目录。 |
||||||||||
public static String |
系统通知铃声存放的标准目录。 |
||||||||||
public static String |
图片存放的标准目录。 |
||||||||||
public static String |
系统广播存放的标准目录。 |
||||||||||
public static String |
系统铃声存放的标准目录。 |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static File |
获得android data的目录。 |
||||||||||
static File |
获得下载缓存目录。 |
||||||||||
static File |
或者外部存储媒体目录。 |
||||||||||
static File |
getExternalStoragePublicDirectory(String type) Get a top-level public external storage directory for placing files of a particular type. |
||||||||||
static String |
获得当前外部储存媒体的状态。 |
||||||||||
static File |
获得android的跟目录。 |
public static File getExternalStoragePublicDirectory (String type)
Get a top-level public external storage directory for placing files of a particular type. This is where the user will typically place and manage their own files, so you should be careful about what you put here to ensure you don't erase their files or get in the way of their own organization.
Here is an example of typical code to manipulate a picture on the public external storage:
void createExternalStoragePublicPicture() {
// Create a path where we will place our picture in the user's
// public pictures directory. Note that you should be careful about
// what you place here, since the user often manages these files. For
// pictures and other media owned by the application, consider
// Context.getExternalMediaDir().
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");
try {
// Make sure the Pictures directory exists.
path.mkdirs();
// Very simple code to copy a picture from the application's
// resource into the external file. Note that this code does
// no error checking, and assumes the picture is small (does not
// try to copy it in chunks). Note that if external storage is
// not currently mounted this will silently fail.
InputStream is = getResources().openRawResource(R.drawable.balloons);
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
// Tell the media scanner about the new file so that it is // 这一步非常重要!!
// immediately available to the user.
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
} catch (IOException e) {
// Unable to create file, likely because external storage is
// not currently mounted.
Log.w("ExternalStorage", "Error writing " + file, e);
}