get USB Size - Android android.os

Android examples for android.os:StatFs

Description

get USB Size

Demo Code

import android.os.StatFs;

public class Main {

  public static long getUSBSize(String path, boolean all) {
    long blocks = 0;

    StatFs sf = new StatFs(path);
    long blockSize = sf.getBlockSize();
    if (all) {//  ww  w. j  av a 2 s. c om
      blocks = sf.getBlockCount();
    } else {
      blocks = sf.getAvailableBlocks();
    }
    return (blocks * blockSize) / 1024 / 1024;
  }

}

Related Tutorials