首页 > 代码库 > 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 判断sd的状态,所有文件,剩余空间的大小
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。