Android's Environment class

Source: Internet
Author: User

String

Media_bad_removal

The storage media has been removed before it is mounted.

String

Media_checking

Checking storage media.

String

media_mounted

The storage media is already mounted and the mount point is read/write.

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 blank or unsupported file system.

String

Media_removed

The storage media is removed.

String

Media_shared

The storage media is being shared via USB.

String

Media_unmountable

Storage media cannot be mounted.

String

media_unmounted

Storage media is not mounted.

Fields

public static String

Directory_alarms

The standard directory where the system reminds the ringtone to be stored.

public static String

Directory_dcim

A standard catalog of photos and videos taken by the camera.

public static String

Directory_downloads

Download the standard Catalog.

public static String

Directory_movies

Standard catalogue for film storage.

public static String

Directory_music

Standard catalogue for music storage.

public static String

Directory_notifications

The system notifies the standard directory where the ringtone is stored.

public static String

Directory_pictures

A standard catalog of picture storage.

public static String

Directory_podcasts

Standard directory for system broadcast storage.

public static String

Directory_ringtones

Standard directory for system ringtone storage.

Public Methods

Static File

Getdatadirectory ()

Get the directory for Android data.

Static File

Getdownloadcachedirectory ()

Get the download cache directory.

Static File

getExternalStorageDirectory ()

Or an external storage media directory.

Static File

Getexternalstoragepublicdirectory (String type)

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

Static String

Getexternalstoragestate ()

Gets the status of the current external storage media.

Static File

Getrootdirectory ()

Get a directory with 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 would typically place and manage their own files, so you should being careful about what to put here T o ensure you don ' t erase their files or get in the the the their own organization.

Here's an example of typical code to manipulate a picture on the public external storage:

voidCreateexternalstoragepublicpicture() { Create a path where we'll place our picture in the user ' s Public Pictures directory. Note that you should is careful about What do you have here, since the user often manages these files. For Pictures and other media owned by the application, consider Context.getexternalmediadir (). FilePath= Environment.Getexternalstoragepublicdirectory( Environment.Directory_pictures); FileFile= 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 was small (does not Try to copy it in chunks). Note that if external storage is Not currently mounted this would silently fail. InputStream Is =Getresources().Openrawresource(R.Drawable.Balloons); OutputStreamOs= New FileOutputStream(File); Byte[]Data= New Byte[Is.Available()]; Is.Read(Data);Os.Write(Data); Is.Close();Os.Close(); Tell the media scanner on the new file so, it is//This step is very important!! Immediately available to the user. Mediascannerconnection.Scanfile(This, New String[] {File.Tostring() }, Null, New Mediascannerconnection.Onscancompletedlistener() { Public voidonscancompleted(StringPath, UriUri) { Log.I("Externalstorage", "Scanned" +Path+ ":"); Log.I("Externalstorage", "Uri=" +Uri); } }); } Catch (IOExceptionE) { Unable to create file, likely because external storage are Not currently mounted. Log.W("Externalstorage", "Error Writing" +File,E); }}voidDeleteexternalstoragepublicpicture() { Create a path where we'll place our picture in the user ' s Public Pictures directory and delete the file. If External Storage is not a currently mounted this would fail. FilePath= Environment.Getexternalstoragepublicdirectory( Environment.Directory_pictures); FileFile= New File(Path, "Demopicture.jpg");File.Delete();}BooleanHasexternalstoragepublicpicture() { Create a path where we'll place our picture in the user ' s Public Pictures directory and check if the file exists. If External storage isn't currently mounted this would think the Picture doesn ' t exist. FilePath= environment. ( environment directory_pictures);  file File =new file (path ,  Span class= "KWD" >return File.               /span>           

Parameters
Type The type of storage directory to return. Should be one of,,,,,,,, DIRECTORY_MUSIC DIRECTORY_PODCASTS DIRECTORY_RINGTONES DIRECTORY_ALARMS DIRECTORY_NOTIFICATIONS DIRECTORY_PICTURES DIRECTORY_MOVIES DIRECTORY_DOWNLOADS or DIRECTORY_DCIM . May isn't null.
Returns
    • Returns the File path for the directory. Note that the This directory is not yet exist, so you must make sure it exists before using it such as with File.mkdirs() .

http://blog.csdn.net/aiqing0119/article/details/7718494

Android's Environment class

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.