获取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();
原文地址:https://www.cnblogs.com/NuoChong/p/10472192.html