【android 判断sd的状态,所有文件,剩余空间的大小】书到用时方恨少,事非经过不知难。这篇文章主要讲述android 判断sd的状态,所有文件,剩余空间的大小相关的知识,希望能为你提供帮助。
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模拟器的路径
- Android中activity传值的两种方式
- android开发实现语音数据实时采集/播放
- Android开发教程
- android杀毒程序
- android pc模拟器
- android x86介绍
- 如何使用CSS创建波浪球效果()
- PHP如何使用cal_days_in_month()函数(代码示例)