android手机内部存储空间和外部存储空间获取代码
2010-08-21 03:22:00 来源:WEB开发网该代码片段可以让我们获取internal和external的存储空间大小。
import java.io.File;
import android.os.Environment;
import android.os.StatFs;
public class MemoryStatus {
private static final String TAG = "***MemoryStatus***";
static final int ERROR = -1;
static public boolean externalMemoryAvailable() {
return android.os.Environment.getExternalStorageState()
.equals(android.os.Environment.MEDIA_MOUNTED);
}
static public long getAvailableInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
static public long getTotalInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return totalBlocks * blockSize;
}
static public long getAvailableExternalMemorySize() {
if(externalMemoryAvailable()) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
} else {
return ERROR;
}
}
static public long getTotalExternalMemorySize() {
if(externalMemoryAvailable()) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
- ››手机丢失防止支付宝资金被盗办法
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
更多精彩
赞助商链接