android的Environment类


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 = 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);
    }
}

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 = new File(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 = new File(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().

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

时间: 2024-10-25 09:00:18

android的Environment类的相关文章

Android Environment 类详解

Android应用开发中,常使用Environment类去获取外部存储目录,在访问外部存储之前一定要先判断外部存储是否已经是可使用(已挂载&可使用)状态, 并且需要在AndroidManifest.xml文件中添加外部存储读和写的权限. 根据官方API文档,接下来对android.os.Environment类做详细介绍. 一.Environment类中提供了多个String类型的静态常量用于标识外部存储媒体的状态. public static final String MEDIA_BAD_RE

Android Environment类的接口详解

Android应用开发中,常使用Environment类去获取外部存储目录,在访问外部存储之前一定要先判断外部存储是否已经是可使用(已挂载&可使用)状态, 并且需要在AndroidManifest.xml文件中添加外部存储读和写的权限. Environment类中提供了几个静态常量用于标识外部存储的状态,这些状态都是String类型 MEDIA_BAD_REMOVAL 在没有挂载前存储媒体已经被移除. MEDIA_CHECKING 正在检查存储媒体. MEDIA_MOUNTED 存储媒体已经挂载

android 文件管理工具类

import java.io.BufferedOutputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;imp

android Loger日志类(获取内置sd卡)

Android手机自带内部存储路径的获取 原文地址:http://my.oschina.net/liucundong/blog/288183 直接贴代码: public static String getExternalSdCardPath() { if (SDCardUtils.isSDCardEnable()) { File sdCardFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath());

Android中Environment与StatFs获取系统/SDCard存储空间大小

近期想起Android开发的知识.好久没有使用了,都忘得几乎相同了,今天查看了一会资料往回捡捡,顺便写下来帮助一下须要的同学. 首先讲述一下Environment与StatFs这两个类,然后介绍它们的具体用法. 1. Environment 类: Environment 是一个提供訪问环境变量的类. Environment 包括常量: MEDIA_BAD_REMOVAL 解释:返回getExternalStorageState() ,表明SDCard 被卸载前己被移除 MEDIA_CHECKIN

android.os.Environment 个人简单理解

Environment类:提供访问环境变量. Android中常用Environment.getExternalStorageState来获取SD卡的状态 SD状态 现象描述 /mnt/sdcard目录是否存在 canRead返回 canWrite返回 在/mnt/sdcard创建文件 在/mnt/sdcard创建文件夹   MEDIA_MOUNTED SD卡正常挂载 TRUE TRUE TRUE TRUE TRUE   MEDIA_REMOVED 无介质 TRUE FALSE FALSE fa

Android日志打印类LogUtils,能够定位到类名,方法名以及出现错误的行数并保存日志文件

关注finddreams,一起分享,一起进步!http://blog.csdn.net/finddreams/article/details/45569089 在开发中,我们常常用打印log的方式来调试我们的应用.在Java中我们常常使用方法System.out.println()来在控制台打印日志,以便我们的调试.Android中有一个专门的类Log来实现在Android系统下日志的打印,更加方便我们定位程序出现问题的地方. 但是Android官方提供的Log类在实际项目使用中,也不是非常方便

Android:通过ThumbnailUtils类获取视频文件的缩略图

在视频播放器上经常会看到,有很多的视频缩略图,本文讲的就是通过ThumbnailUtils类获取视频文件的缩略图; 运行截图如下: 代码如下: MainActivity.java: package com.vrinux.thumbnailutilsdemo; import android.app.Activity; import android.graphics.Bitmap; import android.media.ThumbnailUtils; import android.os.Bund

[Android自定义控件] Android Scroller工具类和GestureDetector的简单用法

转载:http://ipjmc.iteye.com/blog/1615828 Android里Scroller类是为了实现View平滑滚动的一个Helper类.通常在自定义的View时使用,在View中定义一个私有成员mScroller = new Scroller(context).设置mScroller滚动的位置时,并不会导致View的滚动,通常是用mScroller记录/计算View滚动的位置,再重写View的computeScroll(),完成实际的滚动. mScroller.getCu