Java – How to get TOTAL memory and internal storage size in Android?

How to get TOTAL memory and internal storage size in Android?… here is a solution to the problem.

How to get TOTAL memory and internal storage size in Android?

I’m trying to get the total memory (RAM) and internal storage size, but every method I use reports it’s too low. I know the kernel may take up some of it, but I need to know how much is installed in total.

For memory, I first read from /proc/meminfo/ and then use getMemoryInfo. Each of these reports less than the amount of memory installed (700MB instead of 1GB).

For internal storage sizes, I use Environment.getDataDirectory, getBlockSizeLong, and getBlockCountLong 。 This result is much lower than the amount of storage I knew was installed. The settings in the OS are consistent with the number reported by my method, but I need to know the total number of installations, not just the number it thinks is present (even if I type it sounds counterintuitive in my head).

EDIT: I looked at the issues sent and tried their method as I said. The reported value is incorrect compared to the installation I know.

Solution

Memory:

Total RAM available android APP

Basically:

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!

Related Problems and Solutions