我正在開發一個android文件管理器應用程序。 等主要活動我想顯示所有可用的存儲類型,如內部存儲和外部SD卡。獲取內部和外部存儲信息 - android
,所以我用這個代碼,
public static boolean externalMemoryAvailable() {
return android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
}
public static long getAvailableInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
public static long getTotalInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return totalBlocks * blockSize;
}
public static long getAvailableExternalMemorySize() {
if (externalMemoryAvailable()) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
} else {
return 0;
}
}
public static long getTotalExternalMemorySize() {
if (externalMemoryAvailable()) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return totalBlocks * blockSize;
} else {
return 0;
}
}
但問題是,它給我相同的內存輸出,用於內部和外部存儲.. 實際上它給內部存儲正確的答案。但外部SD卡錯誤。
我覺得我錯在獲得ext sd卡的路徑。任何幫助? PLZ。
'但錯誤的外置SD card'。確實。您的代碼中沒有涉及外部SD卡的內容。 – greenapps
'它爲我提供了同樣的內存和外部存儲輸出.'。有趣。確認! – greenapps