1

I need to get the app ram and internal storage in GB (Gigabytes).

I tried this

private void getAppRam() {

        String DeviceModel = android.os.Build.MODEL;
        String DeviceName = android.os.Build.MANUFACTURER;
        String sdk = Build.VERSION.RELEASE;

        System.out.println("DeviceModel...." + DeviceModel);
        System.out.println("DeviceName ...." + DeviceName);
        System.out.println("sdk ...." + sdk);

        ActivityManager actManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
        actManager.getMemoryInfo(memInfo);
        long totalMemory = memInfo.totalMem / (1024 * 1024);
        System.out.println("ram...." + totalMemory);
    }

But did not found accurate results, and can someone suggest any solution for internal storage.

Siddhesh Pawar
  • 259
  • 4
  • 24
  • Possible duplicate of [Getting all the total and available space on Android](https://stackoverflow.com/questions/4799643/getting-all-the-total-and-available-space-on-android) – Aswin P Ashok Jun 22 '18 at 10:41

1 Answers1

0

Here, try this

For getting Total RAM:

private long totalRamMemorySize() {
  ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
  ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
  activityManager.getMemoryInfo(mi);
  long availableMegs = mi.totalMem / 1048576L;
  return availableMegs;
 }

For Getting Total Internal Menory:

public static long getTotalInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return totalBlocks * blockSize;
 }

For more data, Try this Link Get Device RAM and Internal Storage - Induces Smile

Rahul Singh Chandrabhan
  • 2,531
  • 5
  • 22
  • 33