android获取CPU参数(命令行方式)
publicstaticStringfetch_cpu_info(){
Stringresult=null;
try{
String[]args={"/system/bin/cat","/proc/cpuinfo"};
result=run(args,"/system/bin/");
Log.i("result","result="+result);
}catch(IOExceptionex){
ex.printStackTrace();
}
returnresult;
}
publicsynchronizedstaticStringrun(String[]cmd,Stringworkdirectory)
throwsIOException{
Stringresult="";
try{
ProcessBuilderbuilder=newProcessBuilder(cmd);
//设置一个路径
if(workdirectory!=null)
builder.directory(newFile(workdirectory));
builder.redirectErrorStream(true);
Processprocess=builder.start();
InputStreamin=process.getInputStream();
byte[]re=newbyte[1024];
while(in.read(re)!=-1){
result=result+newString(re);
}
in.close();
}catch(Exceptionex){
ex.printStackTrace();
}
returnresult;
}