• 查看Android设备的CPU架构信息


    android系统其实是linux,那么可以在程序中去调用cat /proc/meminfo和cat 
    /proc/cpuino去查看内存和CPU等情况的,下面是程序:

    1. public class CpuSpeed extends Activity {
    2. /** Called when the activity is first created. */
    3.  
    4. private TextView cpuInfo;
    5. private TextView memoryInfo;
    6.  
    7. public void onCreate(Bundle savedInstanceState) {
    8. super.onCreate(savedInstanceState);
    9. setContentView(R.layout.main);
    10. cpuInfo=(TextView)findViewById(R.id.cpuinfo);
    11. cpuInfo.setText(getCPUinfo());
    12. memoryInfo = (TextView)findViewById(R.id.memoryinfo);
    13. memoryInfo.setText(getMemoryInfo());
    14.  
    15. }
    16. private String getMemoryInfo(){
    17. ProcessBuilder cmd;
    18. String result = new String();
    19.  
    20. try{
    21. String[] args = {"/system/bin/cat", "/proc/meminfo"};
    22. cmd = new ProcessBuilder(args);
    23.  
    24. Process process = cmd.start();
    25. InputStream in = process.getInputStream();
    26. byte[] re=new byte[1024];
    27. while (in.read(re)!=-1)
    28. {
    29. System.out.println(new String(re));
    30. result = result + new String(re);
    31.  
    32. }
    33. in.close();
    34. }
    35. catch(IOException ex){
    36. ex.printStackTrace();
    37. }
    38. return result;
    39.  
    40. }
    41. private String getCPUinfo()
    42. {
    43. ProcessBuilder cmd;
    44. String result="";
    45.  
    46. try{
    47. String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
    48. cmd = new ProcessBuilder(args);
    49.  
    50. Process process = cmd.start();
    51. InputStream in = process.getInputStream();
    52. byte[] re = new byte[1024];
    53. while(in.read(re) != -1){
    54. System.out.println(new String(re));
    55. result = result + new String(re);
    56. }
    57. in.close();
    58. } catch(IOException ex){
    59. ex.printStackTrace();
    60. }
    61. return result;
    62. }
     

    }

    其实核心无非就是ProcessBuilder的运用,去启动命令行去读操作系统, 
    String[] args = {"/system/bin/cat", "/proc/cpuinfo"};

    1. cmd = new ProcessBuilder(args);
    2.  
    3. Process process = cmd.start();
    4. InputStream in = process.getInputStream();
     

    然后再IO输入流读入就可以了

  • 相关阅读:
    bzoj 1093: [ZJOI2007]最大半连通子图
    bzoj 1266 1266: [AHOI2006]上学路线route
    poj 2104 K-th Number
    洛谷 P3313 [SDOI2014]旅行
    cogs 306. [SGOI] 糊涂的记者
    cogs 1164. 跑步
    洛谷 1821: [JSOI2010]Group 部落划分 Group
    洛谷 U3357 C2-走楼梯
    洛谷 P3014 [USACO11FEB]牛线Cow Line
    洛谷 P2982 [USACO10FEB]慢下来Slowing down
  • 原文地址:https://www.cnblogs.com/myPersonalTailor/p/4872303.html
Copyright © 2020-2023  润新知