当前位置: 代码迷 >> Android >> Android学习 之 手机跟SD内存信息的一些操作方法
  详细解决方案

Android学习 之 手机跟SD内存信息的一些操作方法

热度:97   发布时间:2016-05-01 17:16:29.0
Android学习 之 手机和SD内存信息的一些操作方法

1。获取可用的内存空间大小信息

public long getAvailMemory() {		ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);		ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();		am.getMemoryInfo(mi);		return mi.availMem;	}

?

2.获取手机内存大小信息

public long[] getRomMemroy() {		long[] romInfo = new long[2];		//Total rom memory		romInfo[0] = getTotalInternalMemorySize();		//Available rom memory		File path = Environment.getDataDirectory();		StatFs stat = new StatFs(path.getPath());		long blockSize = stat.getBlockSize();		long availableBlocks = stat.getAvailableBlocks();		romInfo[1] = blockSize * availableBlocks;		getVersion();		return romInfo;	}	public long getTotalInternalMemorySize() {		File path = Environment.getDataDirectory();		StatFs stat = new StatFs(path.getPath());		long blockSize = stat.getBlockSize();		long totalBlocks = stat.getBlockCount();		return totalBlocks * blockSize;	}

?

3.获取SD卡的内存信息大小

public long[] getSDCardMemory() {		long[] sdCardInfo=new long[2];		String state = Environment.getExternalStorageState();		if (Environment.MEDIA_MOUNTED.equals(state)) {			File sdcardDir = Environment.getExternalStorageDirectory();			StatFs sf = new StatFs(sdcardDir.getPath());			long bSize = sf.getBlockSize();			long bCount = sf.getBlockCount();			long availBlocks = sf.getAvailableBlocks();			sdCardInfo[0] = bSize * bCount;//总大小			sdCardInfo[1] = bSize * availBlocks;//可用大小		}		return sdCardInfo;	}

?

?

4.获取总的内存大小信息

public void getTotalMemory() {		String str1 = "/proc/meminfo";		String str2="";		try {			FileReader fr = new FileReader(str1);			BufferedReader localBufferedReader = new BufferedReader(fr, 8192);			while ((str2 = localBufferedReader.readLine()) != null) {				Log.i(TAG, "---" + str2);			}		} catch (IOException e) {		}	}

?

?

  相关解决方案