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.

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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.
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;

Comments

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;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.