use of android.os.StatFs in project JustAndroid by chinaltz.
the class AbFileUtil method freeSpaceOnSD.
/**
* 计算sdcard上的剩余空间.
*
* @return the int
*/
public static int freeSpaceOnSD() {
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / 1024 * 1024;
return (int) sdFreeMB;
}
use of android.os.StatFs in project smartmodule by carozhu.
the class DeviceInfoUtil method getSDAvailableSize.
/**
* 获得sd卡剩余容量,即可用大小
*
* @return
*/
public String getSDAvailableSize(Context context) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(context, blockSize * availableBlocks);
}
use of android.os.StatFs in project StudyNotes by InnoFang.
the class SDCardUtil method getSDCardAllSize.
/**
* 获取SD卡的剩余容量 单位byte
*
* @return
*/
@SuppressWarnings("deprecation")
public static long getSDCardAllSize() {
if (isSDCardEnable()) {
StatFs stat = new StatFs(getSDCardPath());
//获取空闲的数据块的数量
long availableBlocks = (long) stat.getAvailableBlocks() - 4;
//获取单个数据块的大小(byte)
long freeBlocks = stat.getAvailableBlocks();
return freeBlocks * availableBlocks;
}
return 0;
}
use of android.os.StatFs in project android_packages_apps_Camera by CyanogenMod.
the class Storage method getAvailableSpace.
public long getAvailableSpace() {
String state = Environment.getExternalStorageState();
Log.d(TAG, "External storage state=" + state);
if (Environment.MEDIA_CHECKING.equals(state)) {
return PREPARING;
}
if (!Environment.MEDIA_MOUNTED.equals(state)) {
return UNAVAILABLE;
}
File dir = new File(generateDirectory());
dir.mkdirs();
if (!dir.isDirectory() || !dir.canWrite()) {
return UNAVAILABLE;
}
try {
StatFs stat = new StatFs(generateDirectory());
return stat.getAvailableBlocks() * (long) stat.getBlockSize();
} catch (Exception e) {
Log.i(TAG, "Fail to access external storage", e);
}
return UNKNOWN_SIZE;
}
use of android.os.StatFs in project android_frameworks_base by crdroidandroid.
the class LowStorageTest method onCreate.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// Update the current data info
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
int totalBlocks = stat.getBlockCount();
mBlockSize = (int) (stat.getBlockSize());
TextView startSizeTextView = (TextView) findViewById(R.id.totalsize);
startSizeTextView.setText(Long.toString((totalBlocks * mBlockSize) / BYTE_SIZE));
Button button = (Button) findViewById(R.id.button_run);
button.setOnClickListener(mStartListener);
}
Aggregations