6

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.

jambo
  • 81
  • 1
  • 1
  • 5
  • 2
    possible duplicate of [How to get total RAM size of a device?](http://stackoverflow.com/questions/7374246/how-to-get-total-ram-size-of-a-device) AND [Getting all the total and available space on Android](http://stackoverflow.com/questions/4799643/getting-all-the-total-and-available-space-on-android) Searching the site before asking a question is really helpful to you and the community – prettyvoid Aug 19 '15 at 11:26
  • 1
    As I said in the question I have tried the methods mentioned in those threads. Those methods are reporting values lower than needed. – jambo Aug 19 '15 at 11:56
  • Post the values you're getting from these methods. What value do you get from `memInfo.totalMem`? – prettyvoid Aug 19 '15 at 12:02
  • memInfo.totalMem gives a value of 879MB when the value is set to to 1024MB on the emulator. – jambo Aug 19 '15 at 12:17
  • Such behavior is normal on avds, try the code on a real device and you'll see that it's reporting the correct amount of RAM. – prettyvoid Aug 19 '15 at 12:32

1 Answers1

5

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!

Community
  • 1
  • 1
Fer
  • 460
  • 2
  • 4
  • 17
  • Duplicate questions are better forwarded to their duplicate threads rather than answering them, in my opinion. – prettyvoid Aug 19 '15 at 11:29
  • 2
    As I said I've tried using `getMemoryInfo` it reports 700KB instead of 1GB. as for storage I need the **Internal** storage space. – jambo Aug 19 '15 at 11:55
  • @prettyvoid I agree but those are two previous answers combined. Thanks – Fer Aug 21 '15 at 14:12