Could anyone help me how to get processor name, speed and RAM of Android device via code.
What to Know. Tap Settings > About Phone > RAM to view the amount of RAM your phone has. Tap Settings > About Phone > Build Version several times to activate Developer Options to view advanced RAM info.
You can get processor, RAM and other hardware related information as we normally get in Linux. From terminal we can issue these command in a normal Linux system. You don't need to have a rooted device for this.
$ 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();
}
its only possible on a rooted device or your app is running as system application.
For wanted informations you have to look in the running kernel, as i know this informations cant be obtained by the android system itself.
To obtain informations about the CPU, you can read and parse this file: /proc/cpuinfo
To obtain memory informations, you can read and parse this file: /proc/memory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With