How to get total RAM size of a device?

前端 未结 5 501
囚心锁ツ
囚心锁ツ 2020-12-01 08:20

I want to get full RAM size of a device. memoryInfo.getTotalPss() returns 0. There is not function for get total RAM size in ActivityManager.MemoryInfo.

5条回答
  •  粉色の甜心
    2020-12-01 08:29

    As of API level 16 you can now use the totalMem property of the MemoryInfo class.

    Like this:

    ActivityManager actManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
    actManager.getMemoryInfo(memInfo);
    long totalMemory = memInfo.totalMem;
    

    Api level 15 and lower still requires to use the unix command as shown in cweiske's answer.

提交回复
热议问题