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(); }
source share