title: How to get actual size of mounted SD card in Android?
body: <p>I'm trying to find a way to find the total size and free space of a mounted SD card on a phone, from my research on SOF and on the Android devs site I was able to find the method getExternalStorageDirectory() but according to the <a href="http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()" rel="nofollow noreferrer">Android API</a> this returns a directory that is not necessarily external:</p>
  
  <p>"Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer."</p>
  
  <p>So I gather from the way that is worded that the "external storage" directory can actually be apart of multiple physical storage devices (internal and external memory). And from my testing that's what I've found as the size that is being returned by using this method is around 1.5x the size of my actual SD card.</p>
  
  <p>So my question is, is there a programmatical way to return the total size and available space just on the SD card? The phone itself can give me that information so I feel like there should be a way but I'm at a loss right now... any help would be appreciated!</p>
  
  <p>EDIT:
  This is the code I'm currently using for total size</p>
  
  <pre><code>private long TotalSDMemory(){
      File path = Environment.getExternalStorageDirectory();
      StatFs stat = new StatFs(path.getAbsolutePath());
      long blockSize = stat.getBlockSize();
      long totalBlocks = stat.getBlockCount();
      long totalSpace = totalBlocks * blockSize;
      Log.d(TAG,"Size of total SD Memory: "+totalSpace);
      Log.d(TAG, "External storage emulated: "+Environment.isExternalStorageEmulated());
      return totalSpace;
  }
  </code></pre>
  
  <p>Edit(2):
  I didn't know this mattered but I have a Samsung Galaxy S3 which is what I am using to test the code, apparently Samsung has a different file structure for their external memory. Here is a link that should help anyone else get the correct size:
  <a href="https://stackoverflow.com/questions/12087510/check-if-the-sdcard-is-present-boolean-is-always-true">Get size of SD card in Samsung phones</a></p>