How to get TOTAL memory and internal storage size Android?

旧时模样 提交于 2019-12-10 18:46:39

问题


I'm attempting to get the total memory (RAM) and internal storage size, but every method I have used is reporting it too low. I'm aware the kernel may take up some of it but I need to know how much there is installed in total.

For the memory I first just read from /proc/meminfo/ then used the getMemoryInfo. Each of these reported less than the amount of memory installed (700MB instead of 1GB).

for the internal storage size I am using Environment.getDataDirectory, getBlockSizeLong and getBlockCountLong. The result of this is much lower than the amount of storage I know is installed. The settings in the OS agree with the amount reported by my method but I need to know the total amount installed not just what it thinks is there (Even as I typed that it sounded counter-intuitive in my head).

Edit: I've looked at the questions that are being sent and tried their methods as I said. The values reported are incorrect compared for what I know is installed.


回答1:


for RAM:

Total RAM available android APP

Basically is:

MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;

Storage:

Available STORAGE Android APP

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;

Good luck!



来源:https://stackoverflow.com/questions/32094038/how-to-get-total-memory-and-internal-storage-size-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!