Android程式設計獲取手機型號,本機電話號碼,sdk版本及firmware版本號(即系統版本號)

狼人2007發表於2014-08-09

  Android開發平臺中,可通過TelephonyManager 獲取本機號碼。


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

String MODEL The end-user-visible name for the end product.

  sdk版本 Build.VERSION.SDK

String SDK This constant is deprecated. Use SDK_INT to easily get this as an integer.

  及frimware版本號(系統版本號) Build.VERSION.RELEASE

String RELEASE The user-visible version string.

private void loadPhoneStatus()
{
TelephonyManager phoneMgr
=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
txtPhoneModel.setText(Build.MODEL);
//手機型號
txtPhoneNumber.setText(phoneMgr.getLine1Number());//本機電話號碼
txtSdkVersion.setText(Build.VERSION.SDK);//SDK版本號
txtOsVersion.setText(Build.VERSION.RELEASE);//Firmware/OS 版本號
}

  事實上,Build能向我們提供包括 硬體廠商,硬體編號,序列號等很多資訊 呼叫方法也都同上,很簡單。

String BOARD The name of the underlying board, like “goldfish”.
String BOOTLOADER The system bootloader version number.
String BRAND The brand (e.g., carrier) the software is customized for, if any.
String CPU_ABI The name of the instruction set (CPU type + ABI convention) of native code.
String CPU_ABI2 The name of the second instruction set (CPU type + ABI convention) of native code.
String DEVICE The name of the industrial design.
String DISPLAY A build ID string meant for displaying to the user
String FINGERPRINT A string that uniquely identifies this build.
String HARDWARE The name of the hardware (from the kernel command line or /proc).
String HOST  
String ID Either a changelist number, or a label like “M4-rc20”.
String MANUFACTURER The manufacturer of the product/hardware.
String MODEL The end-user-visible name for the end product.
String PRODUCT The name of the overall product.
String RADIO The radio firmware version number.
String SERIAL A hardware serial number, if available.
String TAGS Comma-separated tags describing the build, like “unsigned,debug”.
long TIME  
String TYPE The type of build, like “user” or “eng”.
String UNKNOWN Value used for when a build property is unknown.
String USER

  最近在做韓國一家公司的Android平臺軟體開發,我的手機號是韓國的啦。所以看到010打頭的號碼,別太驚訝..

  我的twitter: @mainroadlee 

  手頭做的專案涉及到Android平臺中網路設定,資料庫,http協議下的資料傳輸,支付系統,以及SNS API(twitter, facebook, me2day, etc), QR碼掃描等模組。

  如果大家感興趣的話,我會在開發閒暇時間陸續將常用的一些模組的開發呼叫,寫成獨立,簡潔的教程發上來。


相關文章