private void updateMemorySize() {
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED)) {
try {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
// free/total memory in the SD card
tvFlashCardCapacity.setText(”SD card: ”
+ formatMemorySize(availableBlocks * blockSize) + ” / ”
+ formatMemorySize(totalBlocks * blockSize));
} catch (IllegalArgumentException e) {
// this can occur if the SD card is removed, but we haven’t
// received the
// ACTION_MEDIA_REMOVED Intent yet.
status = Environment.MEDIA_REMOVED;
}
} else {
tvFlashCardCapacity.setText(”SD card: unavailable”);
}
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
// free/total memory in the internal memory
tvInternalMemoryCapacity.setText(”Internal memory: ”
+ formatMemorySize(availableBlocks * blockSize) + ” / ”
+ formatMemorySize(totalBlocks * blockSize));
}