android开发——获取手机SD卡的容量

   今天写了一个小巧但是实用的应用,获取手机sdcard 的容量,主要是通过总容量=分区数量*分区总数这个公式得到的。直接贴上代码。


sdnumberView = (TextView) this.findViewById(R.id.sdnumber);
        //获取sd卡目录
        File path = Environment.getExternalStorageDirectory();
        //把sd卡目录传进去
        StatFs statFs = new StatFs(path.getPath());
        long count = statFs.getBlockCount();
        long size = statFs.getBlockSize();
        String text = count*size+"";
        sdnumberView.setText(text);