TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
txtPhoneNumber.setText(phoneMgr.getLine1Number()); //txtPhoneNumber是一個EditText 用于顯示手機号
注:根據Android的安全機制,在使用TelephonyManager時,必須在AndroidManifest.xml中添加<uses-permission android:name="READ_PHONE_STATE" /> 否則無法獲得系統的許可。
手機型号 Build.MODEL
<a href="http://developer.android.com/reference/java/lang/String.html">String</a>
<a href="http://developer.android.com/reference/android/os/Build.html#MODEL">MODEL</a>
The end-user-visible name for the end product.
sdk版本 Build.VERSION.SDK
<a href="http://developer.android.com/reference/android/os/Build.VERSION.html#SDK">SDK</a>
及frimware版本号(系統版本号) Build.VERSION.RELEASE
<a href="http://developer.android.com/reference/android/os/Build.VERSION.html#RELEASE">RELEASE</a>
The user-visible version string.
private void loadPhoneStatus()
{
txtPhoneModel.setText(Build.MODEL); //手機型号
txtPhoneNumber.setText(phoneMgr.getLine1Number());//本機電話号碼
txtSdkVersion.setText(Build.VERSION.SDK);//SDK版本号
txtOsVersion.setText(Build.VERSION.RELEASE);//Firmware/OS 版本号
}
事實上,Build能向我們提供包括 硬體廠商,硬體編号,序列号等很多資訊 調用方法也都同上,很簡單。
<a href="http://developer.android.com/reference/android/os/Build.html#BOARD">BOARD</a>
The name of the underlying board, like "goldfish".
<a href="http://developer.android.com/reference/android/os/Build.html#BOOTLOADER">BOOTLOADER</a>
The system bootloader version number.
<a href="http://developer.android.com/reference/android/os/Build.html#BRAND">BRAND</a>
The brand (e.g., carrier) the software is customized for, if any.
<a href="http://developer.android.com/reference/android/os/Build.html#CPU_ABI">CPU_ABI</a>
The name of the instruction set (CPU type + ABI convention) of native code.
<a href="http://developer.android.com/reference/android/os/Build.html#CPU_ABI2">CPU_ABI2</a>
The name of the second instruction set (CPU type + ABI convention) of native code.
<a href="http://developer.android.com/reference/android/os/Build.html#DEVICE">DEVICE</a>
The name of the industrial design.
<a href="http://developer.android.com/reference/android/os/Build.html#DISPLAY">DISPLAY</a>
A build ID string meant for displaying to the user
<a href="http://developer.android.com/reference/android/os/Build.html#FINGERPRINT">FINGERPRINT</a>
A string that uniquely identifies this build.
<a href="http://developer.android.com/reference/android/os/Build.html#HARDWARE">HARDWARE</a>
The name of the hardware (from the kernel command line or /proc).
<a href="http://developer.android.com/reference/android/os/Build.html#HOST">HOST</a>
<a href="http://developer.android.com/reference/android/os/Build.html#ID">ID</a>
Either a changelist number, or a label like "M4-rc20".
<a href="http://developer.android.com/reference/android/os/Build.html#MANUFACTURER">MANUFACTURER</a>
The manufacturer of the product/hardware.
<a href="http://developer.android.com/reference/android/os/Build.html#PRODUCT">PRODUCT</a>
The name of the overall product.
<a href="http://developer.android.com/reference/android/os/Build.html#RADIO">RADIO</a>
The radio firmware version number.
<a href="http://developer.android.com/reference/android/os/Build.html#SERIAL">SERIAL</a>
A hardware serial number, if available.
<a href="http://developer.android.com/reference/android/os/Build.html#TAGS">TAGS</a>
Comma-separated tags describing the build, like "unsigned,debug".
long
<a href="http://developer.android.com/reference/android/os/Build.html#TIME">TIME</a>
<a href="http://developer.android.com/reference/android/os/Build.html#TYPE">TYPE</a>
The type of build, like "user" or "eng".
<a href="http://developer.android.com/reference/android/os/Build.html#UNKNOWN">UNKNOWN</a>
Value used for when a build property is unknown.
<a href="http://developer.android.com/reference/android/os/Build.html#USER">USER</a>
最近在做南韓一家公司的Android平台軟體開發,我的手機号是南韓的啦。是以看到010打頭的号碼,别太驚訝..
我的twitter: @mainroadlee
手頭做的項目涉及到Android平台中網絡設定,資料庫,http協定下的資料傳輸,支付系統,以及SNS API(twitter, facebook, me2day, etc), QR碼掃描等子產品。
如果大家感興趣的話,我會在開發閑暇時間陸續将常用的一些子產品的開發調用,寫成獨立,簡潔的教程發上來。