How to programmatically find the CPU load of any Android device
•
Android
I want the same details in my android app. Does anyone have any solution?
resolvent:
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 information:
> How to get CPU usage statistics on Android? > Get cpu info programmatically on android application > How I get CPU usage and temperature information into an android app? > https://www.android-examples.com/get-android-device-cpu-information-programmatically/
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码