Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. private String ReadCPUinfo()
  2. {
  3. ProcessBuilder cmd;
  4. String result="";
  5.  
  6. try{
  7. String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
  8. cmd = new ProcessBuilder(args);
  9.  
  10. Process process = cmd.start();
  11. InputStream in = process.getInputStream();
  12. byte[] re = new byte[1024];
  13. while(in.read(re) != -1){
  14. System.out.println(new String(re));
  15. result = result + new String(re);
  16. }
  17. in.close();
  18. } catch(IOException ex){
  19. ex.printStackTrace();
  20. }
  21. return result;
  22. }
  23.  
  24. device.setText(Html.fromHtml(
  25. "CPU Speed: " + readUsage() * 100
  26. ));
  27.  
  28. Timer timer = new Timer();
  29. MyTimerTask myTimerTask = new MyTimerTask();
  30.  
  31. timer.schedule(myTimerTask, 0, 1000); // 0 Delay, Repeat after 1 second
  32.  
  33. class MyTimerTask extends TimerTask
  34. {
  35. public void run()
  36. {
  37. runOnUiThread(new Runnable()
  38. {
  39. @Override
  40. public void run()
  41. {
  42. device.setText(Html.fromHtml("CPU Speed: " + readUsage() * 100));
  43. }
  44. }
  45. }
  46. }
  47.  
  48. device.postDelayed(new Runnable()
  49. {
  50. @Override
  51. public void run()
  52. {
  53. device.setText(Html.fromHtml("CPU Speed: " + readUsage() * 100));
  54. }
  55. }, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement