The Android system is actually Linux, so you can call CAT/proc/meminfo and Cat in the program
/Proc/cpuino to view the memory and CPU conditions, the following is the program:
Public class cpuspeed extends activity {
/** Called when the activity is first created .*/
Private textview cpuinfo;
Private textview memoryinfo;
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Cpuinfo = (textview) findviewbyid (R. Id. cpuinfo );
Cpuinfo. settext (getcpuinfo ());
Memoryinfo = (textview) findviewbyid (R. Id. memoryinfo );
Memoryinfo. settext (getmemoryinfo ());
}
Private string getmemoryinfo (){
Processbuilder cmd;
String result = new string ();
Try {
String [] ARGs = {"/system/bin/cat", "/proc/meminfo "};
Cmd = new processbuilder (ARGs );
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;
}
Private string getcpuinfo ()
{
Processbuilder cmd;
String result = "";
Try {
String [] ARGs = {"/system/bin/cat", "/proc/cpuinfo "};
Cmd = new processbuilder (ARGs );
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;
}
}
In fact, the core is nothing more than the use of processbuilder, to start the command line to read the operating system,
String [] ARGs = {"/system/bin/cat", "/proc/cpuinfo "};
Cmd = new processbuilder (ARGs );
Process = cmd. Start ();
Inputstream in = process. getinputstream ();
Then read the IO input stream.