Android編程實現獲得內存剩余大小與總大小的方法
更新時間:2015年12月02日 11:14:19 作者:lee0oo0
這篇文章主要介紹了Android編程實現獲得內存剩余大小與總大小的方法,涉及Android基于ActivityManager實現內存信息的操作技巧,需要的朋友可以參考下
本文實例講述了Android編程實現獲得內存剩余大小與總大小的方法。分享給大家供大家參考,具體如下:
public class memInfo { // 獲得可用的內存 public static long getmem_UNUSED(Context mContext) { long MEM_UNUSED; // 得到ActivityManager ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); // 創(chuàng)建ActivityManager.MemoryInfo對象 ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); am.getMemoryInfo(mi); // 取得剩余的內存空間 MEM_UNUSED = mi.availMem / 1024; return MEM_UNUSED; } // 獲得總內存 public static long getmem_TOLAL() { long mTotal; // /proc/meminfo讀出的內核信息進行解釋 String path = "/proc/meminfo"; String content = null; BufferedReader br = null; try { br = new BufferedReader(new FileReader(path), 8); String line; if ((line = br.readLine()) != null) { content = line; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } // beginIndex int begin = content.indexOf(':'); // endIndex int end = content.indexOf('k'); // 截取字符串信息 content = content.substring(begin + 1, end).trim(); mTotal = Integer.parseInt(content); return mTotal; } }
希望本文所述對大家Android程序設計有所幫助。
您可能感興趣的文章:
- Android獲取SD卡路徑及SDCard內存的方法
- android讀取sdcard路徑下的文件的方法
- 獲取android4.0版本sdcard路徑示例
- Android實現把文件存放在SDCard的方法
- android中把文件保存到sdcard代碼實例
- Android中使用SDcard讀取文件
- Android編程獲取sdcard卡信息的方法
- Android實現獲取SD卡總容量,可用大小,機身內存總容量及可用大小的方法
- Android獲取設備CPU核數、時鐘頻率以及內存大小的方法
- android開發(fā)教程之用命令啟動android模擬器并設置其內存大小
- Android開發(fā)實現的獲取sdcard大小及內存大小工具類
相關文章
Android中用StaticLayout實現文本繪制自動換行詳解
StaticLayout是android中處理文字換行的一個工具類,StaticLayout已經實現了文本繪制換行處理,下面這篇文章主要介紹了Android中用StaticLayout實現文本繪制自動換行的相關資料,需要的朋友可以參考。2017-03-03