use of android.os.StatFs in project storymaker by StoryMaker.
the class MediaProjectManager method checkStorageSpace.
// return space required to pass info up the stack
public double checkStorageSpace() {
ArrayList<Media> mList = this.mProject.getMediaAsList();
Long totalBytesRequired = 0l;
//first check that all of the input images are accessible
for (Media media : mList) {
try {
if (media == null || media.getPath() == null) {
} else if (!new File(media.getPath()).exists()) {
throw new java.io.FileNotFoundException();
} else {
File currentFile = new File(media.getPath());
totalBytesRequired += (long) currentFile.length();
}
} catch (java.io.FileNotFoundException fnfe) {
Timber.e(fnfe, "Input image does not exist or is not readable" + ": " + media.getPath());
}
}
//get memory path
String memoryPath;
if (mUseInternal) {
memoryPath = Environment.getDataDirectory().getPath();
} else {
memoryPath = Environment.getExternalStorageDirectory().getPath();
}
//get memory
StatFs stat = new StatFs(memoryPath);
Long totalBytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
// FIXME we should raise this error via a intent, not a straight toast so it can be handled if the activity is hidden
if (totalBytesRequired > totalBytesAvailable) {
double totalMBRequired = totalBytesRequired / (double) (1024 * 1024);
// can't create toast message here because instances created by renderer have a null value for activity
return totalMBRequired;
}
return 0;
}
use of android.os.StatFs in project tinker by Tencent.
the class Utils method checkRomSpaceEnough.
@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
long allSize;
long availableSize = 0;
try {
File data = Environment.getDataDirectory();
StatFs sf = new StatFs(data.getPath());
availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize();
allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize();
} catch (Exception e) {
allSize = 0;
}
if (allSize != 0 && availableSize > limitSize) {
return true;
}
return false;
}
use of android.os.StatFs in project SeriesGuide by UweTrottmann.
the class HttpClientModule method calculateApiDiskCacheSize.
private static long calculateApiDiskCacheSize(File dir) {
long size = MIN_DISK_API_CACHE_SIZE;
try {
StatFs statFs = new StatFs(dir.getAbsolutePath());
long available;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
available = statFs.getBlockCountLong() * statFs.getBlockSizeLong();
} else {
//noinspection deprecation
available = ((long) statFs.getBlockCount()) * statFs.getBlockSize();
}
// Target 2% of the total space.
size = available / 50;
} catch (IllegalArgumentException ignored) {
}
// Bound inside min/max size for disk cache.
return Math.max(Math.min(size, MAX_DISK_API_CACHE_SIZE), MIN_DISK_API_CACHE_SIZE);
}
use of android.os.StatFs in project atlas by alibaba.
the class ReplacedReceiver method getAvailableInternalMemorySize.
private long getAvailableInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
use of android.os.StatFs in project SmartAndroidSource by jaychou2012.
the class SystemInfo method getSDCardAvailableStorage.
/**
* Get the Device's SDCardAvailableStorage
*
* @return the Device's SDCardAvailableStorage
*/
public String getSDCardAvailableStorage() {
long[] sdCardInfo = new long[2];
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File sdcardDir = Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(sdcardDir.getPath());
long bSize = sf.getBlockSize();
long bCount = sf.getBlockCount();
long availBlocks = sf.getAvailableBlocks();
sdCardInfo[1] = bSize * availBlocks;
}
return sdCardInfo[1] / (1024 * 1024) + "MB";
}
Aggregations