Android編程實現(xiàn)獲得內(nèi)存剩余大小與總大小的方法
更新時間:2015年12月02日 11:14:19 作者:lee0oo0
這篇文章主要介紹了Android編程實現(xiàn)獲得內(nèi)存剩余大小與總大小的方法,涉及Android基于ActivityManager實現(xiàn)內(nèi)存信息的操作技巧,需要的朋友可以參考下
本文實例講述了Android編程實現(xiàn)獲得內(nèi)存剩余大小與總大小的方法。分享給大家供大家參考,具體如下:
public class memInfo {
// 獲得可用的內(nèi)存
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);
// 取得剩余的內(nèi)存空間 MEM_UNUSED = mi.availMem / 1024;
return MEM_UNUSED;
}
// 獲得總內(nèi)存
public static long getmem_TOLAL() {
long mTotal;
// /proc/meminfo讀出的內(nèi)核信息進行解釋
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程序設(shè)計有所幫助。
您可能感興趣的文章:
- Android獲取SD卡路徑及SDCard內(nèi)存的方法
- android讀取sdcard路徑下的文件的方法
- 獲取android4.0版本sdcard路徑示例
- Android實現(xiàn)把文件存放在SDCard的方法
- android中把文件保存到sdcard代碼實例
- Android中使用SDcard讀取文件
- Android編程獲取sdcard卡信息的方法
- Android實現(xiàn)獲取SD卡總?cè)萘浚捎么笮?,機身內(nèi)存總?cè)萘考翱捎么笮〉姆椒?/a>
- Android獲取設(shè)備CPU核數(shù)、時鐘頻率以及內(nèi)存大小的方法
- android開發(fā)教程之用命令啟動android模擬器并設(shè)置其內(nèi)存大小
- Android開發(fā)實現(xiàn)的獲取sdcard大小及內(nèi)存大小工具類
相關(guān)文章
Android中用StaticLayout實現(xiàn)文本繪制自動換行詳解
StaticLayout是android中處理文字換行的一個工具類,StaticLayout已經(jīng)實現(xiàn)了文本繪制換行處理,下面這篇文章主要介紹了Android中用StaticLayout實現(xiàn)文本繪制自動換行的相關(guān)資料,需要的朋友可以參考。2017-03-03
Android?Flutter實現(xiàn)任意拖動的控件
使用flutter開發(fā)是需要控件能拖動,比如畫板中的元素,或者工具條等,所以本文為大家準備了Flutter實現(xiàn)任意拖動控件的示例代碼,希望對大家有所幫助2023-07-07

