Android 查看可用存储内存大小
2010-05-24 21:06:00 来源:WEB开发网下面为查看可用存储内存大小的示例,用于查看和内部和外部存储器的总存储。
view sourceprint? 01import java.io.File;
02
03import android.os.Environment;
04import android.os.StatFs;
05
06public class MemoryStatus {
07
08static final int ERROR = -1;
09
10static public boolean externalMemoryAvailable() {
11return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
12}
13
14static public long getAvailableInternalMemorySize() {
15File path = Environment.getDataDirectory();
16StatFs stat = new StatFs(path.getPath());
17long blockSize = stat.getBlockSize();
18long availableBlocks = stat.getAvailableBlocks();
19return availableBlocks * blockSize;
20}
21
22static public long getTotalInternalMemorySize() {
23File path = Environment.getDataDirectory();
24StatFs stat = new StatFs(path.getPath());
25long blockSize = stat.getBlockSize();
26long totalBlocks = stat.getBlockCount();
27return totalBlocks * blockSize;
28}
29
30static public long getAvailableExternalMemorySize() {
31if(externalMemoryAvailable()) {
32File path = Environment.getExternalStorageDirectory();
33StatFs stat = new StatFs(path.getPath());
34long blockSize = stat.getBlockSize();
35long availableBlocks = stat.getAvailableBlocks();
36return availableBlocks * blockSize;
37} else {
38return ERROR;
39}
40}
41
42static public long getTotalExternalMemorySize() {
43if(externalMemoryAvailable()) {
44File path = Environment.getExternalStorageDirectory();
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接