0
我使用下面的代碼來獲得CPU的percetange(類似62.5465%),但它似乎需要很長時間來刷新/更新,除非您手動導航到另一個活動,然後回來。有沒有辦法強制信息每秒更新一次?任何herlp將不勝感激。強制刷新/更新數據讀取
private String ReadCPUinfo()
{
ProcessBuilder cmd;
String result="";
try{
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
return result;
}
用於在TextView中顯示文本。
device.setText(Html.fromHtml(
"CPU Speed: " + readUsage() * 100
));