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
- 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能向我们提供包括 硬件厂商,硬件编号,序列号等很多信息 调用方法也都同上,下面是Build中的API中定义。
public static final String | BOARD | The name of the underlying board, like "goldfish". |
public static final String | BOOTLOADER | The system bootloader version number. |
public static final String | BRAND | The brand (e.g., carrier) the software is customized for, if any. |
public static final String | CPU_ABI | The name of the instruction set (CPU type + ABI convention) of native code. |
public static final String | CPU_ABI2 | The name of the second instruction set (CPU type + ABI convention) of native code. |
public static final String | DEVICE | The name of the industrial design. |
public static final String | DISPLAY | A build ID string meant for displaying to the user |
public static final String | FINGERPRINT | A string that uniquely identifies this build. |
public static final String | HARDWARE | The name of the hardware (from the kernel command line or /proc). |
public static final String | HOST | |
public static final String | ID | Either a changelist number, or a label like "M4-rc20". |
public static final String | MANUFACTURER | The manufacturer of the product/hardware. |
public static final String | MODEL | The end-user-visible name for the end product. |
public static final String | PRODUCT | The name of the overall product. |
public static final String | RADIO | The radio firmware version number. |
public static final String | SERIAL | A hardware serial number, if available. |
public static final String | TAGS | Comma-separated tags describing the build, like "unsigned,debug". |
public static final long | TIME | |
public static final String | TYPE | The type of build, like "user" or "eng". |
public static final String | USER |
效果图: