TShopping

 找回密碼
 註冊
搜索
查看: 1860|回復: 0
打印 上一主題 下一主題

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2016-2-4 22:44:10 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook

佈局文件, main.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:orientation="vertical"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     >
  7. <TextView
  8.     android:layout_width="fill_parent"
  9.     android:layout_height="wrap_content"
  10.     android:text="@string/hello"
  11.     />
  12. <TextView
  13.     android:layout_width="fill_parent"
  14.     android:layout_height="wrap_content"
  15.     android:text="android.os.Build"
  16.     android:background="#505050"
  17.     />
  18. <TextView
  19.     android:id="@+id/device"
  20.     android:layout_width="fill_parent"
  21.     android:layout_height="wrap_content"
  22.     />
  23. <TextView
  24.     android:id="@+id/model"
  25.     android:layout_width="fill_parent"
  26.     android:layout_height="wrap_content"
  27.     />
  28. <TextView
  29.     android:id="@+id/product"
  30.     android:layout_width="fill_parent"
  31.     android:layout_height="wrap_content"
  32.     />
  33. <TextView
  34.     android:layout_width="fill_parent"
  35.     android:layout_height="wrap_content"
  36.     android:text="android.os.Build.VERSION"
  37.     android:background="#505050"
  38.     />
  39. <TextView
  40.     android:id="@+id/codename"
  41.     android:layout_width="fill_parent"
  42.     android:layout_height="wrap_content"
  43.     />
  44. <TextView
  45.     android:id="@+id/incremental"
  46.     android:layout_width="fill_parent"
  47.     android:layout_height="wrap_content"
  48.     />
  49. <TextView
  50.     android:id="@+id/release"
  51.     android:layout_width="fill_parent"
  52.     android:layout_height="wrap_content"
  53.     />
  54. <TextView
  55.     android:id="@+id/sdk"
  56.     android:layout_width="fill_parent"
  57.     android:layout_height="wrap_content"
  58.     />
  59. <TextView
  60.     android:id="@+id/sdk_int"
  61.     android:layout_width="fill_parent"
  62.     android:layout_height="wrap_content"
  63.     />
  64. <TextView
  65.     android:layout_width="fill_parent"
  66.     android:layout_height="wrap_content"
  67.     android:text="System.getProperty()"
  68.     android:background="#505050"
  69.     />
  70. <TextView
  71.     android:id="@+id/os_arch"
  72.     android:layout_width="fill_parent"
  73.     android:layout_height="wrap_content"
  74.     />
  75. <TextView
  76.     android:id="@+id/os_name"
  77.     android:layout_width="fill_parent"
  78.     android:layout_height="wrap_content"
  79.     />
  80. <TextView
  81.     android:id="@+id/os_version"
  82.     android:layout_width="fill_parent"
  83.     android:layout_height="wrap_content"
  84.     />
  85. </LinearLayout>
複製代碼


程序代碼
  1. package com.AndroidSysInfo;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.widget.TextView;

  5. public class AndroidSysInfo extends Activity {
  6.     /** Called when the activity is first created. */
  7.     @Override
  8.     public void onCreate(Bundle savedInstanceState) {
  9.         super.onCreate(savedInstanceState);
  10.         setContentView(R.layout.main);
  11.         TextView textDevice = (TextView)findViewById(R.id.device);
  12.         TextView textModel = (TextView)findViewById(R.id.model);
  13.         TextView textProduct = (TextView)findViewById(R.id.product);
  14.          
  15.         TextView textCodename = (TextView)findViewById(R.id.codename);
  16.         TextView textIncremental = (TextView)findViewById(R.id.incremental);
  17.         TextView textRelease = (TextView)findViewById(R.id.release);
  18.         TextView textSdk = (TextView)findViewById(R.id.sdk);
  19.         TextView textSdkInt = (TextView)findViewById(R.id.sdk_int);
  20.          
  21.         TextView textOS_Arch = (TextView)findViewById(R.id.os_arch);
  22.         TextView textOS_Name = (TextView)findViewById(R.id.os_name);
  23.         TextView textOS_Version = (TextView)findViewById(R.id.os_version);
  24.          
  25.         textDevice.setText(".DEVICE: " + android.os.Build.DEVICE);
  26.         textModel.setText(".MODEL: " + android.os.Build.MODEL);
  27.         textProduct.setText(".PRODUCT: " + android.os.Build.PRODUCT);
  28.          
  29.         textCodename.setText(".CODENAME: " + android.os.Build.VERSION.CODENAME);
  30.         textIncremental.setText(".INCREMENTAL: " + android.os.Build.VERSION.INCREMENTAL);
  31.         textRelease.setText(".RELEASE: " + android.os.Build.VERSION.RELEASE);
  32.         textSdk.setText(".SDK: " + android.os.Build.VERSION.SDK);
  33.         textSdkInt.setText(".SDK_INT: " + String.valueOf(android.os.Build.VERSION.SDK_INT));
  34.          
  35.         textOS_Arch.setText("os.arch: " + System.getProperty("os.arch"));
  36.         textOS_Name.setText("os.name: " + System.getProperty("os.name"));
  37.         textOS_Version.setText("os.version: " + System.getProperty("os.version"));
  38.     }
  39. }
複製代碼


文章來源

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-24 10:48 , Processed in 0.058776 second(s), 25 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表