Reputation: 2896
I am trying to programatically find the system info for Android devices, specifically:
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.
Upvotes: 6
Views: 15505
Reputation: 186
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;
Upvotes: 2
Reputation: 485
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;
}
Upvotes: 1
Reputation: 34775
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.
Upvotes: 11
Reputation: 20319
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
Upvotes: 2