Use new StatFS API if available

This commit is contained in:
daniel oeh 2013-09-20 23:24:16 +02:00
parent e579618dae
commit e4fa17d7d0
1 changed files with 10 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import java.io.File;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.StatFs; import android.os.StatFs;
import android.util.Log; import android.util.Log;
import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.AppConfig;
@ -51,8 +52,15 @@ public class StorageUtils {
public static long getFreeSpaceAvailable() { public static long getFreeSpaceAvailable() {
StatFs stat = new StatFs(UserPreferences.getDataFolder( StatFs stat = new StatFs(UserPreferences.getDataFolder(
PodcastApp.getInstance(), null).getAbsolutePath()); PodcastApp.getInstance(), null).getAbsolutePath());
long availableBlocks = stat.getAvailableBlocks(); long availableBlocks;
long blockSize = stat.getBlockSize(); long blockSize;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
availableBlocks = stat.getAvailableBlocksLong();
blockSize = stat.getBlockSizeLong();
} else {
availableBlocks = stat.getAvailableBlocks();
blockSize = stat.getBlockSize();
}
return availableBlocks * blockSize; return availableBlocks * blockSize;
} }
} }