I want to have the same details in my android app. Anybody having any solution?
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
public class MainActivity extends AppCompatActivity {
TextView textView ;
ProcessBuilder processBuilder;
String Holder = "";
String[] DATA = {"/system/bin/cat", "/proc/cpuinfo"};
InputStream inputStream;
Process process ;
byte[] byteArry ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textView);
byteArry = new byte[1024];
try{
processBuilder = new ProcessBuilder(DATA);
process = processBuilder.start();
inputStream = process.getInputStream();
while(inputStream.read(byteArry) != -1){
Holder = Holder + new String(byteArry);
}
inputStream.close();
} catch(IOException ex){
ex.printStackTrace();
}
textView.setText(Holder);
}
}
More info:
Since Android is based on a modified version of the Linux kernel, the same Linux command we can use to retrieve the CPU information according to the documentation.
This virtual file identifies the type of processor used by your system - /proc/cpuinfo
The command can be executed through ADB shell
ADB Command:
adb shell cat /proc/cpuinfo
Using ProcessBuilder
in Java API, you can execute the shell command from the Android application as below.
Java API:
try {
String[] DATA = {"/system/bin/cat", "/proc/cpuinfo"};
ProcessBuilder processBuilder = new ProcessBuilder(DATA);
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
byte[] byteArry = new byte[1024];
String output = "";
while (inputStream.read(byteArry) != -1) {
output = output + new String(byteArry);
}
inputStream.close();
Log.d("CPU_INFO", output);
} catch (Exception ex) {
ex.printStackTrace();
}
Sample output:
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