Androidでメモリ(RAM)情報を取得
Javaコード:
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) {
}
}
実行結果:
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —MemTotal: 204876 kB
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —MemFree: 4596 kB
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —Buffers: 16020 kB
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —Cached: 82508 kB
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —SwapCached: 64 kB
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —Active: 137104 kB
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —Inactive: 41056 kB
07-26 08:05:14.807: INFO/-SystemInfo-(1519): —SwapTotal: 65528 kB
07-26 08:05:14.817: INFO/-SystemInfo-(1519): —SwapFree: 65368 kB
07-26 08:05:14.817: INFO/-SystemInfo-(1519): —Dirty: 88 kB
07-26 08:05:14.817: INFO/-SystemInfo-(1519): —Writeback: 0 kB
07-26 08:05:14.817: INFO/-SystemInfo-(1519): —AnonPages: 79672 kB
07-26 08:05:14.817: INFO/-SystemInfo-(1519): —Mapped: 38296 kB
07-26 08:05:14.817: INFO/-SystemInfo-(1519): —Slab: 5768 kB
07-26 08:05:14.817: INFO/-SystemInfo-(1519): —SReclaimable: 1856 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —SUnreclaim: 3912 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —PageTables: 8184 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —NFS_Unstable: 0 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —Bounce: 0 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —CommitLimit: 167964 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —Committed_AS: 11771920 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —VmallocTotal: 761856 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —VmallocUsed: 83656 kB
07-26 08:05:14.827: INFO/-SystemInfo-(1519): —VmallocChunk: 674820 kB
現在残っているメモリ(RAM)サイズを取得
public long getAvailMemory() {
ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem;
}