Programmatically find information about the Android system

I am trying to programmatically find system information for Android devices, in particular:

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

Are there Android classes that specify this information. I am using the android.board library, but it does not seem to have everything that I want.

+6
source share
4 answers

Let me tell you what I did, so others who visit this thread can learn about the steps:

1) command parse / proc / meminfo. The link code can be found here: Get memory usage in Android 2) use the code below and get the 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 only need to calculate shared memory once. therefore, call point 1 only once in your code, and then after that you can re-call the code of point 2.

+11
source

You can get most of the information from the /proc/cpuinfo file. Here is a tutorial on downloading and analyzing this file: http://www.roman10.net/how-to-get-cpu-information-on-android/

In addition, RAM information can be obtained from the file /proc/meminfo

+2
source

Below is a code snippet to get the current RAM size of the device.

 ActivityManager actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); MemoryInfo memInfo = new ActivityManager.MemoryInfo(); actManager.getMemoryInfo(memInfo); long totalMemory = memInfo.totalMem; 
+2
source

Agarwal's answer was very helpful. I had to change it a little, since I do not calculate the free memory in activity, but transfer the system utilities file in the application context:

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; } 
+1
source

Source: https://habr.com/ru/post/913584/


All Articles