我找到了一种非常好的方法来获取设备所拥有的所有SD卡的路径,不仅包括Environment.getExternalStorageDirectory(),还包括外部路径。此方法适用于How can I get external SD card path for Android 4.0+?
所以,我的问题是我怎样才能找到sd卡上的免费可用空间知道它的路径,例如“storage / extSdCard”或任何其他
换句话说我需要一种方法:
public int getExternalAvailableSpaceInBytes(String sdRootPath) {
//here's this method using this sdRootPath
}
答案 0 :(得分:-1)
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){
@SuppressWarnings("deprecation")
long sdAvailSize = (long)stat.getAvailableBlocksLong() * (long)stat.getBlockSizeLong();
}
else{
@SuppressWarnings("deprecation")
double sdAvailSize = (double)stat.getAvailableBlocks() * (double)stat.getBlockSize();
}
double gigaAvailable = sdAvailSize / 1073741824; //1073741824 =1GB