获取sd卡空间大小和获取sd卡目录

Posted nuochong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取sd卡空间大小和获取sd卡目录相关的知识,希望对你有一定的参考价值。

获取sd卡空间大小

       TextView tv_total_size = (TextView)findViewById(R.id.textView1);
        TextView tv_useable_size = (TextView)findViewById(R.id.textView2);
        
        File file =Environment.getExternalStorageDirectory();
        long totalSpace = file.getTotalSpace();
        long usableSpace = file.getUsableSpace();
        
        String formatToatalSpace = Formatter.formatFileSize(this, totalSpace);
        String formatUsableSpace =Formatter.formatFileSize(this, usableSpace);
        
        tv_total_size.setText("总大小:"+formatToatalSpace);
        tv_useable_size.setText("可用空间:"+formatUsableSpace);

获取sd 卡目录

String sdPath =Environment.getExternalStorageDirectory().getPath();

 

以上是关于获取sd卡空间大小和获取sd卡目录的主要内容,如果未能解决你的问题,请参考以下文章