/* 判断记忆卡是否插入 */
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
/* 取得SD CARD档案路径一般是/sdcard */
File path = Environment.getExternalStorageDirectory();
/* StatFs看文件系统空间使用状况 */
StatFs statFs = new StatFs(path.getPath());
/* Block的size */
long blockSize = statFs.getBlockSize();
/* 总Block数量 */
long totalBlocks = statFs.getBlockCount();
/* 已使用的Block数量 */
long availableBlocks = statFs.getAvailableBlocks();
String[] total = fileSize(totalBlocks * blockSize);
String[] available = fileSize(availableBlocks * blockSize);
/* getMax取得在main.xml里ProgressBar设定的最大值 */
int ss = Integer.parseInt(available[0]) * myProgressBar.getMax() / Integer.parseInt(total[0]);
myProgressBar.setProgress(ss);
String text = "总共" + total[0] + total[1] + "\n"; text += "可用" + available[0] + available[1];
myTextView.setText(text); }
else if (Environment.getExternalStorageState().equals( Environment.MEDIA_REMOVED))
{
String text = "SD CARD已移除"; myTextView.setText(text);
}
}
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
/* 取得SD CARD档案路径一般是/sdcard */
File path = Environment.getExternalStorageDirectory();
/* StatFs看文件系统空间使用状况 */
StatFs statFs = new StatFs(path.getPath());
/* Block的size */
long blockSize = statFs.getBlockSize();
/* 总Block数量 */
long totalBlocks = statFs.getBlockCount();
/* 已使用的Block数量 */
long availableBlocks = statFs.getAvailableBlocks();
String[] total = fileSize(totalBlocks * blockSize);
String[] available = fileSize(availableBlocks * blockSize);
/* getMax取得在main.xml里ProgressBar设定的最大值 */
int ss = Integer.parseInt(available[0]) * myProgressBar.getMax() / Integer.parseInt(total[0]);
myProgressBar.setProgress(ss);
String text = "总共" + total[0] + total[1] + "\n"; text += "可用" + available[0] + available[1];
myTextView.setText(text); }
else if (Environment.getExternalStorageState().equals( Environment.MEDIA_REMOVED))
{
String text = "SD CARD已移除"; myTextView.setText(text);
}
}