码迷,mamicode.com
首页 > 移动开发 > 详细

android 判断sd的状态,所有文件,剩余空间的大小

时间:2016-12-09 10:29:43      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:can   equals   空间   ide   tor   stat   get   set   ppc   

public class MainActivity extends AppCompatActivity {

String TAG = MainActivity.class.getCanonicalName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String storageState = Environment.getExternalStorageState();
//sd卡的状态
Log.e(TAG, "onCreate: "+storageState );
Log.e(TAG, "onCreate: "+Environment.MEDIA_MOUNTED );
//判断是否有sd卡
boolean equals = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
Log.e(TAG, "onCreate: "+equals);
//得到sd卡的路径
String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
Log.e(TAG, "onCreate: "+absolutePath );

//得到内置sd卡内所有的文件
File file = Environment.getExternalStorageDirectory();
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
Log.e(TAG, "onCreate: "+files[i] );
}
long freeSpace = Environment.getExternalStorageDirectory().getFreeSpace();
long usableSpace = Environment.getExternalStorageDirectory().getUsableSpace();
long totalSpace = Environment.getExternalStorageDirectory().getTotalSpace();
Log.e(TAG, "onCreate: 剩余空间大小:"+freeSpace/1024/1024+" 可用大小:"+usableSpace/1024/1024+" 总空间大小:"+totalSpace/1024/1024 );

}
}

demo下载地址:https://github.com/renjiemei1225/ExtraTest

android 判断sd的状态,所有文件,剩余空间的大小

标签:can   equals   空间   ide   tor   stat   get   set   ppc   

原文地址:http://www.cnblogs.com/renjiemei1225/p/6148433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!