2012-02-20 84 views
4

任何人都可以幫助我如何通過代碼獲取Android設備的處理器名稱,速度和RAM。如何在Android設備中獲取處理器速度和RAM

+0

這有幫助嗎? http://stackoverflow.com/questions/4875415/how-to-detect-android-cpu-speed – 2012-02-20 14:30:59

+0

http://stackoverflow.com/questions/2201112/retrieving-device-information-on-android – 2012-02-20 14:32:57

回答

4

其唯一可能在根設備上或您的應用程序作爲系統應用程序運行。

對於想要的信息,你必須看看正在運行的內核,因爲我知道這個信息 不能被android系統本身獲得。

要獲取信息有關的CPU,你可以閱讀和分析此文件: 的/ proc/cpuinfo中

爲了獲得內存的信息,你可以閱讀和分析此文件: 的/ proc /內存

19

您可以獲得像我們通常在Linux中獲得的處理器,RAM和其他硬件相關的信息。 從終端我們可以在普通的Linux系統中發出這些命令。您不需要需要有一個根源設備爲此。

$ cat /proc/cpuinfo 

同樣,您可以在android代碼中發出這些命令並獲得結果。

public void getCpuInfo() { 
    try { 
     Process proc = Runtime.getRuntime().exec("cat /proc/cpuinfo"); 
     InputStream is = proc.getInputStream(); 
     TextView tv = (TextView)findViewById(R.id.tvcmd); 
     tv.setText(getStringFromInputStream(is)); 
    } 
    catch (IOException e) { 
     Log.e(TAG, "------ getCpuInfo " + e.getMessage()); 
    } 
} 

public void getMemoryInfo() { 
    try { 
     Process proc = Runtime.getRuntime().exec("cat /proc/meminfo"); 
     InputStream is = proc.getInputStream(); 
     TextView tv = (TextView)findViewById(R.id.tvcmd); 
     tv.setText(getStringFromInputStream(is)); 
    } 
    catch (IOException e) { 
     Log.e(TAG, "------ getMemoryInfo " + e.getMessage()); 
    } 
} 

private static String getStringFromInputStream(InputStream is) { 
    StringBuilder sb = new StringBuilder(); 
    BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
    String line = null; 

    try { 
     while((line = br.readLine()) != null) { 
      sb.append(line); 
      sb.append("\n"); 
     } 
    } 
    catch (IOException e) { 
     Log.e(TAG, "------ getStringFromInputStream " + e.getMessage()); 
    } 
    finally { 
     if(br != null) { 
      try { 
       br.close(); 
      } 
      catch (IOException e) { 
       Log.e(TAG, "------ getStringFromInputStream " + e.getMessage()); 
      } 
     } 
    }  

    return sb.toString(); 
} 
+1

工程像黃油 – Sandeep 2013-10-27 10:34:54