WEB开发网
开发学院手机开发Android 开发 android手机内部存储空间和外部存储空间获取代码 阅读

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

该代码片段可以让我们获取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();

1 2  下一页

Tags:android 手机 内部

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