get SD Card Size - Android android.os

Android examples for android.os:SD Card

Description

get SD Card Size

Demo Code

import java.io.File;

import android.os.Environment;
import android.os.StatFs;

public class Main {

  public static long getSDSize(boolean all) {
    long blocks = 0;
    File path = Environment.getExternalStorageDirectory();
    StatFs sf = new StatFs(path.getPath());
    long blockSize = sf.getBlockSize();
    if (all) {/*w ww  .j  a  v a2  s.com*/
      blocks = sf.getBlockCount();
    } else {
      blocks = sf.getAvailableBlocks();
    }
    return (blocks * blockSize) / 1024 / 1024; // ?????MB
  }

}

Related Tutorials