WEB开发网
开发学院手机开发Android 开发 Android 查看可用存储内存大小 阅读

Android 查看可用存储内存大小

 2010-05-24 21:06:00 来源:WEB开发网   
核心提示:下面为查看可用存储内存大小的示例,用于查看和内部和外部存储器的总存储,Android 查看可用存储内存大小,view sourceprint? 01import java.io.File;0203import android.os.Environment;04import android.os.StatFs;0506p

下面为查看可用存储内存大小的示例,用于查看和内部和外部存储器的总存储。

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();

1 2  下一页

Tags:Android 查看 可用

编辑录入:coldstar [复制链接] [打 印]
赞助商链接