AndroidでSDcardサイズを取得

Javaコード:
public long[] getSDCardMemory() {
long[] sdCardInfo=new long[2];
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File sdcardDir = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(sdcardDir.getPath());
long bSize = sf.getBlockSize();
long bCount = sf.getBlockCount();
long availBlocks = sf.getAvailableBlocks();

sdCardInfo[0] = bSize * bCount;//総サイズ
sdCardInfo[1] = bSize * availBlocks;//利用可能サイズ
}
return sdCardInfo;
}

Java

Posted by arkgame