Sunday, 19 October 2014

How we can check our hardware in android

1. Check out Hardware details with simple tutorial :-

package system_detail;

import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;

import com.example.spynew.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class hardware_detail_tab extends Activity {
TextView CPU;
TextView MEMORY;
TextView DISPLAY;
String display_info;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hardware_detail_tab);
CPU=(TextView)findViewById(R.id.cpu);
CPU.setText(ReadCPUinfo());
MEMORY=(TextView)findViewById(R.id.memory);
MEMORY.setText(getTotalRAM());
DISPLAY=(TextView)findViewById(R.id.display);
}

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;
}
public static String getTotalRAM() {
   RandomAccessFile reader = null;
   String load = null;
   try {
       reader = new RandomAccessFile("/proc/meminfo", "r");
       load = reader.readLine();
   } catch (IOException ex) {
       ex.printStackTrace();
   } finally {
       // Streams.close(reader);
   }
   return load;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

No comments:

Post a Comment