6

I am trying to programatically find the system info for Android devices, specifically:

  • RAM
  • CPU speed
  • # cores, architecture, etc.

Are there any Android classes that specify this information. I have been using the android.board library, but it doesn't seem to have everything that I want.

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
Chris Ridmann
  • 2,706
  • 4
  • 15
  • 18

4 Answers4

11

Let me tell you what I did, So others who visit this thread can come to know the steps:

1) parse /proc/meminfo command. You can find reference code here: Get Memory Usage in Android 2) use below code and get current RAM:

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

Note: please note that - we need to calculate total memory only once. so call point 1 only once in your code and then after, you can call code of point 2 repetitively.

Community
  • 1
  • 1
Shankar Agarwal
  • 39,320
  • 8
  • 68
  • 66
2

You can get most of the information you want from the /proc/cpuinfo file. Here is a tutorial on how to load and parse that file: http://www.roman10.net/how-to-get-cpu-information-on-android/

Additionally the information about the RAM can be obtained from the /proc/meminfo file

slayton
  • 19,732
  • 8
  • 57
  • 86
  • meminfo will not give you the full installed ram. it gives you information about used ram. and hot it is used. so the answer is not correct. – drdrej Mar 19 '14 at 12:26
2

Here is the code snippet to get the current device RAM size.

ActivityManager actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem;
Amit Pathak
  • 168
  • 3
1

Agarwal's answer was very helpful. Had to modify it a bit since I'm not calculating free memory in an activity, but passing in an application context to a system utilities file:

From the main activity:

public class MyActivity extends Activity {
    ...
    public void onCreate(Bundle savedInstanceState) {
        ...
        MySystemUtils systemUtils = new MySystemUtils(this); // initializations
        ...
     }
}

In the SystemUtils file:

   MySystemUtils (Context appContext) { // called once from within onCreate
        MemoryInfo mi = new MemoryInfo();
        ActivityManager activityManager = ActivityManager)appContext.getSystemService(Activity.ACTIVITY_SERVICE);
        activityManager.getMemoryInfo(mi);
        long availableMegs = mi.availMem / 1048576L;
    }
Dan
  • 485
  • 6
  • 9