How to get processor speed and RAM in an Android device

Can someone help me get the processor name, speed and RAM of an Android device using code.

+4
source share
2 answers

it is only possible on the root device, or your application runs as a system application.

To get the necessary information you need to look in the running kernel, since I know this information cannot be obtained by the android system itself.

To get information about the CPU, you can read and analyze this file: / Proc / CPUInfo

To get memory information, you can read and analyze this file: / Proc / memory

+4
source

You can get the processor, RAM and other information related to the hardware, as we usually get in Linux. From the terminal, we can issue this command on a regular Linux system. For this, it is not necessary to have a root device .

$ cat /proc/cpuinfo 

Similarly, you can issue these commands in Android code and get the result.

 public void getCpuInfo() { try { Process proc = Runtime.getRuntime().exec("cat /proc/cpuinfo"); InputStream is = proc.getInputStream(); TextView tv = (TextView)findViewById(R.id.tvcmd); tv.setText(getStringFromInputStream(is)); } catch (IOException e) { Log.e(TAG, "------ getCpuInfo " + e.getMessage()); } } public void getMemoryInfo() { try { Process proc = Runtime.getRuntime().exec("cat /proc/meminfo"); InputStream is = proc.getInputStream(); TextView tv = (TextView)findViewById(R.id.tvcmd); tv.setText(getStringFromInputStream(is)); } catch (IOException e) { Log.e(TAG, "------ getMemoryInfo " + e.getMessage()); } } private static String getStringFromInputStream(InputStream is) { StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; try { while((line = br.readLine()) != null) { sb.append(line); sb.append("\n"); } } catch (IOException e) { Log.e(TAG, "------ getStringFromInputStream " + e.getMessage()); } finally { if(br != null) { try { br.close(); } catch (IOException e) { Log.e(TAG, "------ getStringFromInputStream " + e.getMessage()); } } } return sb.toString(); } 
+19
source

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


All Articles