Environment class of android, record it

Source: Internet
Author: User

String

MEDIA_BAD_REMOVAL

The storage media has been removed before being mounted.

String

MEDIA_CHECKING

Checking storage media.

String

MEDIA_MOUNTED

The storage media has been mounted and the mount point is readable/written.

String

MEDIA_MOUNTED_READ_ONLY

The storage media has been mounted and the mount point is read-only.

String

MEDIA_NOFS

The storage media is a blank or unsupported file system.

String

MEDIA_REMOVED

The storage media is removed.

String

MEDIA_SHARED

Storage media is being shared via USB.

String

MEDIA_UNMOUNTABLE

Storage media cannot be mounted.

String

MEDIA_UNMOUNTED

The storage media is not mounted.

 

 

Fields

Public static String

DIRECTORY_ALARMS

The standard directory for storing system notification ringtones.

Public static String

DIRECTORY_DCIM

The standard directory of photos and videos taken by the camera.

Public static String

DIRECTORY_DOWNLOADS

The downloaded standard directory.

Public static String

DIRECTORY_MOVIES

The standard directory for storing movies.

Public static String

DIRECTORY_MUSIC

Standard Directory for music storage.

Public static String

Directory_configurications

Standard Directory for storing system notification ringtones.

Public static String

DIRECTORY_PICTURES

Standard Directory for storing images.

Public static String

DIRECTORY_PODCASTS

Standard Directory for system broadcast storage.

Public static String

DIRECTORY_RINGTONES

Standard Directory for storing system ringtones.

 

 

 

 

Public Methods

Static File

GetDataDirectory ()

Obtain the android data directory.

Static File

GetDownloadCacheDirectory ()

Obtain the download cache directory.

Static File

GetExternalStorageDirectory ()

Or an external media directory.

Static File

GetExternalStoragePublicDirectory (String type)

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

Static String

GetExternalStorageState ()

Obtain the status of the current external storage media.

Static File

GetRootDirectory ()

Obtain the android directory.

 

 

 

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

Get a top-level public external storage directory for placing files of a particle type. this is where the user will typically place and manage their own files, so you shoshould 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 shoshould 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 (Environme Nt. 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 t His 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 transfer about the new file so that it is // this step is very important !! // 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. shocould be oneDIRECTORY_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 asFile.mkdirs().

The above content is taken from the google android development document

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.