2012-02-20 8 views

答えて

4

は、ルートデバイスでのみ可能です。そうでないと、システムアプリケーションとして実行されていません。

私はこの情報を知っているので、実行中のカーネルを調べる必要がある情報については、 はアンドロイドシステム自体では取得できません。

CPUについての情報を入手するには、このファイルを読み込んで解析することができます: は/ proc/cpuinfoの

メモリ情報を入手するには、このファイルを読み込んで解析することができます: は/ proc /メモリ

19

私たちが普通にLinuxで入手しているように、プロセッサ、RAM、その他のハードウェア関連の情報を得ることができます。 端末からは、通常のLinuxシステムでこれらのコマンドを発行できます。あなたルーテッドデバイスが必要です。

$ cat /proc/cpuinfo 

同様に、これらのコマンドをアンドロイドコードで発行して結果を得ることができます。

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

関連する問題