Chinaunix首页 | 论坛 | 博客
  • 博客访问: 822045
  • 博文数量: 210
  • 博客积分: 10002
  • 博客等级: 上将
  • 技术积分: 1840
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-18 09:56
文章分类

全部博文(210)

文章存档

2011年(1)

2010年(6)

2009年(65)

2008年(138)

我的朋友

分类: LINUX

2009-12-15 19:50:44

Android CPU info. can be retrieved by reading of "/proc/cpuinfo". So, it's just a very little bit of modification on Read Android OS version.



Create a new Android Application, with the Activity named AndroidCPUinfoActivity. Modify the main.xml and AndroidCPUinfoActivity.java:

main.xml


android="android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="android-er.blogspot.com"
android:autoLink="web"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Android CPU Info.:"
/>
android:id="@+id/CPUinfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>


Download main.xml.

AndroidCPUinfoActivity.java
package com.exercise.AndroidCPUinfo;

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

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

public class AndroidCPUinfoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

TextView CPUinfo = (TextView) findViewById(R.id.CPUinfo);
CPUinfo.setText(ReadCPUinfo());

}

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;
}
}

阅读(3709) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~