android的Environment类
2015-08-25 13:55
459 查看
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”);
}
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 of DIRECTORY_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开发文
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”);
[code]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 of DIRECTORY_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开发文
相关文章推荐
- 解决Android Studio Gradle DSL method not found: 'android()'
- Android通知栏颜色改变方法
- android 为TextView添加边框
- Android 开发知识点总结
- 关于Android数据库的小结
- Android得到屏幕分辨率
- Android中实现全屏、无标题栏的两种办法
- Android Design Support Library概览
- Android插件化开发之OpenAtlas插件启动方式与插件启动广播
- android-studio 快捷键
- Android应用程序资源(一)
- 使用Ant打包Android应用详解——Ant使用解析
- 自定义一个可以嵌套在ScrollView中使用的ListView和GridView
- Android Api Demos登顶之路(四十七)Loader-->Throttle
- Android自定义RelativeLayout,使宽度和高度一样
- Android studio 快捷键之——【智能提示】
- Android 监听系统音乐播放器播放的音乐的方法
- Android开发中字符串比较,新手容易出错
- android context 问题记录
- Android NDK封装非系统第3方so库