use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.
the class CommonUtil method getSDcardTotalSize.
/**
* 获取手机SD卡总空间
*/
private static long getSDcardTotalSize() {
if (checkSdCard()) {
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long blockCountLong = mStatFs.getBlockCountLong();
return blockSizeLong * blockCountLong;
} else {
return 0;
}
}
use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.
the class CommonUtil method getSDcardAvailableSize.
/**
* 获取SDka可用空间
*/
private static long getSDcardAvailableSize() {
if (checkSdCard()) {
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long availableBlocksLong = mStatFs.getAvailableBlocksLong();
return blockSizeLong * availableBlocksLong;
} else {
return 0;
}
}
use of android.os.StatFs in project bilibili-android-client by HotBitmapGG.
the class CommonUtil method getPhoneTotalSize.
/**
* 获取手机内部存储总空间
*/
public static long getPhoneTotalSize() {
if (!checkSdCard()) {
File path = Environment.getDataDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long blockCountLong = mStatFs.getBlockCountLong();
return blockSizeLong * blockCountLong;
} else {
return getSDcardTotalSize();
}
}
use of android.os.StatFs in project AndroidChromium by JackyAndroid.
the class SpaceDisplay method createStorageSizeTask.
private AsyncTask<Void, Void, Long> createStorageSizeTask() {
return new AsyncTask<Void, Void, Long>() {
@Override
protected Long doInBackground(Void... params) {
File downloadDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// Create the downloads directory, if necessary.
if (!downloadDirectory.exists()) {
try {
// mkdirs() can fail, so we still need to check if the directory exists
// later.
downloadDirectory.mkdirs();
} catch (SecurityException e) {
Log.e(TAG, "SecurityException when creating download directory.", e);
}
}
// Determine how much space is available on the storage device where downloads
// reside. If the downloads directory doesn't exist, it is likely that the user
// doesn't have an SD card installed.
long fileSystemBytes = 0;
if (downloadDirectory.exists()) {
StatFs statFs = new StatFs(downloadDirectory.getPath());
long totalBlocks = ApiCompatibilityUtils.getBlockCount(statFs);
long blockSize = ApiCompatibilityUtils.getBlockSize(statFs);
fileSystemBytes = totalBlocks * blockSize;
} else {
Log.e(TAG, "Download directory doesn't exist.");
}
return fileSystemBytes;
}
};
}
use of android.os.StatFs in project QuickAndroid by ImKarl.
the class QAFileManager method getDataAvailableSize.
/**
* 获取手机内部可用大小
* @return
*/
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getDataAvailableSize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
if (QASdkVersion.isSupport(QASdkVersion.JELLY_BEAN_MR2)) {
return stat.getAvailableBytes();
} else {
long availableBlocks = stat.getAvailableBlocks();
long blockSize = stat.getBlockSize();
return availableBlocks * blockSize;
}
}
Aggregations