2011年2月4日星期五

通過android.os.Build和System.getProperty()獲取系統信息(SysInfo)

HTC Wildfire的系統信息(SysInfo)

佈局文件, main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="android.os.Build"
android:background="#505050"
/>
<TextView
android:id="@+id/device"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/model"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/product"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="android.os.Build.VERSION"
android:background="#505050"
/>
<TextView
android:id="@+id/codename"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/incremental"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/release"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/sdk"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/sdk_int"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="System.getProperty()"
android:background="#505050"
/>
<TextView
android:id="@+id/os_arch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/os_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/os_version"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>


程序代碼
package com.AndroidSysInfo;

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

public class AndroidSysInfo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textDevice = (TextView)findViewById(R.id.device);
TextView textModel = (TextView)findViewById(R.id.model);
TextView textProduct = (TextView)findViewById(R.id.product);

TextView textCodename = (TextView)findViewById(R.id.codename);
TextView textIncremental = (TextView)findViewById(R.id.incremental);
TextView textRelease = (TextView)findViewById(R.id.release);
TextView textSdk = (TextView)findViewById(R.id.sdk);
TextView textSdkInt = (TextView)findViewById(R.id.sdk_int);

TextView textOS_Arch = (TextView)findViewById(R.id.os_arch);
TextView textOS_Name = (TextView)findViewById(R.id.os_name);
TextView textOS_Version = (TextView)findViewById(R.id.os_version);

textDevice.setText(".DEVICE: " + android.os.Build.DEVICE);
textModel.setText(".MODEL: " + android.os.Build.MODEL);
textProduct.setText(".PRODUCT: " + android.os.Build.PRODUCT);

textCodename.setText(".CODENAME: " + android.os.Build.VERSION.CODENAME);
textIncremental.setText(".INCREMENTAL: " + android.os.Build.VERSION.INCREMENTAL);
textRelease.setText(".RELEASE: " + android.os.Build.VERSION.RELEASE);
textSdk.setText(".SDK: " + android.os.Build.VERSION.SDK);
textSdkInt.setText(".SDK_INT: " + String.valueOf(android.os.Build.VERSION.SDK_INT));

textOS_Arch.setText("os.arch: " + System.getProperty("os.arch"));
textOS_Name.setText("os.name: " + System.getProperty("os.name"));
textOS_Version.setText("os.version: " + System.getProperty("os.version"));
}
}


沒有留言:

發佈留言