new Thread() {
@Override
public void run() {
StringBuilder tv = new StringBuilder();
int rate = 0;
try {
String Result;
Process p;
p = Runtime.getRuntime().exec("top -n 1");
InputStream in = p.getInputStream();
if (android.os.Build.VERSION.SDK_INT >= 26) {
LogUtil.i("cpu", "Result Android8.0+ ");
byte[] re = new byte[1024];
while (in.read(re) != -1) {
tv = tv.append(new String(re));
}
LogUtil.i("cpu", "Result Android8.0+ tv " + tv.toString());
} else {
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((Result = br.readLine()) != null) {
if (Result.trim().length() < 1) {
continue;
} else {
LogUtil.i("cpu", "Result " + Result.toString());
break;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();