android的Environment類,記錄一下

來源:互聯網
上載者:User

String

MEDIA_BAD_REMOVAL

在沒有掛載前儲存媒體已經被移除。

String

MEDIA_CHECKING

正在檢查儲存媒體。

String

MEDIA_MOUNTED

儲存媒體已經掛載,並且掛載點可讀/寫。

String

MEDIA_MOUNTED_READ_ONLY

儲存媒體已經掛載,掛載點唯讀。

String

MEDIA_NOFS

儲存媒體是空白或是不支援的檔案系統。

String

MEDIA_REMOVED

儲存媒體被移除。

String

MEDIA_SHARED

儲存媒體正在通過USB共用。

String

MEDIA_UNMOUNTABLE

儲存媒體無法掛載。

String

MEDIA_UNMOUNTED

儲存媒體沒有掛載。

 

 

Fields

public static String

DIRECTORY_ALARMS

系統提醒鈴聲存放的標準目錄。

public static String

DIRECTORY_DCIM

相機拍攝照片和視頻的標準目錄。

public static String

DIRECTORY_DOWNLOADS

下載的標準目錄。

public static String

DIRECTORY_MOVIES

電影存放的標準目錄。

public static String

DIRECTORY_MUSIC

音樂存放的標準目錄。

public static String

DIRECTORY_NOTIFICATIONS

系統通知鈴聲存放的標準目錄。

public static String

DIRECTORY_PICTURES

圖片存放的標準目錄。

public static String

DIRECTORY_PODCASTS

系統廣播存放的標準目錄。

public static String

DIRECTORY_RINGTONES

系統鈴聲存放的標準目錄。

 

 

 

 

Public Methods

static File

getDataDirectory()

獲得android data的目錄。

static File

getDownloadCacheDirectory()

獲得下載快取目錄。

static File

getExternalStorageDirectory()

或者外部儲存媒體目錄。

static File

getExternalStoragePublicDirectory(String type)

Get a top-level public external storage directory for placing files of a particular type.

static String

getExternalStorageState()

獲得當前外部儲存媒體的狀態。

static File

getRootDirectory()

獲得android的跟目錄。

 

 

 

public static File getExternalStoragePublicDirectory (String type)Since: API Level 8

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 =newFile(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.InputStreamis= getResources().openRawResource(R.drawable.balloons);OutputStream os =newFileOutputStream(file);byte[] data =newbyte[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,newString[]{ file.toString()},null,newMediaScannerConnection.OnScanCompletedListener(){publicvoid 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);}}void deleteExternalStoragePublicPicture(){// Create a path where we will place our picture in the user's// public pictures directory and delete the file.  If external// storage is not currently mounted this will fail.File path =Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);File file =newFile(path,"DemoPicture.jpg");    file.delete();}boolean hasExternalStoragePublicPicture(){// Create a path where we will place our picture in the user's// public pictures directory and check if the file exists.  If// external storage is not currently mounted this will think the// picture doesn't exist.File path =Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);File file =newFile(path,"DemoPicture.jpg");return file.exists();}

 

Parameters
type The type of storage directory to return. Should be one ofDIRECTORY_MUSIC,DIRECTORY_PODCASTS,DIRECTORY_RINGTONES,DIRECTORY_ALARMS,DIRECTORY_NOTIFICATIONS,DIRECTORY_PICTURES,DIRECTORY_MOVIES,DIRECTORY_DOWNLOADS, orDIRECTORY_DCIM. May not be null.
Returns
  • Returns the File path for the directory. Note that this directory may not yet exist, so you must make sure it exists before using it such as withFile.mkdirs().

以上內容摘自google android開發文

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.