`
zhouxiaoli521
  • 浏览: 553262 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)

阅读更多

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

=================================================

首先我们来明确几个概念:

SIM卡存储的数据可分为四类:

第一类是固定存放的数据。这类数据在移动电话机被出售之前由SIM卡中心写入,包括国际移动用户识别号(IMSI)、鉴权密钥(KI)、鉴权和加密算法等等。

第二类是暂时存放的有关网络的数据。如位置区域识别码(LAI)、移动用户暂时识别码(TMSI)、禁止接入的公共电话网代码等。

第三类是相关的业务代码,如个人识别码(PIN)、解锁码(PUK)、计费费率等。

第四类是电话号码簿,是手机用户随时输入的电话号码。用户全部资料几乎都存储在SIM卡内,因此SIM卡又称为用户资料识别卡。

IMSI是一个唯一的数字, 标识了GSMUMTS 网络里的唯一一个用户. 它存储 在手机的SIM卡里,它会通过手机发送到网络上. IMSI SIM唯一对应

IMEI也是一串唯一的数字, 标识了 GSM UMTS网络里的唯一一个手机.它通常被打印在手机里电池下面的那一面,拨 *#06# 也能看到它. IMEI 设备唯一对应.

1IMEI不存在于SIM卡中,它是手机本身的串号。
2
。通常我们所说的手机号也不存在于SIM卡中,虽然SIM卡中有一个专门存储SIM卡本身号码的地方,但是此号码是通过手工设定的,而且是可以更改的。 SIM卡的识别通常使用IMSI号,这个对于SIM卡是唯一的。

3
。使用SimGetRecordInfo之类的函数获得SIM卡的IMSI号码能否成功依赖于设备制造商是否实现了此函数,据我所知在DOPOD的机器上是可以获得,但是在联想的机器上却不行,其他机器没有。

4
。获得IMEI以及IMSI可以通过RIL或者TAPI中的LINE操作的函数获得。

下面给出获取手机本机号码的代码:

TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

String deviceid = tm.getDeviceId();

String tel = tm.getLine1Number();

String imei = tm.getSimSerialNumber();

String imsi = tm.getSubscriberId();

添加权限:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

 

注意,手机号码不是所有的都能获取。只是有一部分可以拿到。这个是由于移动运营商没有把手机号码的数据写入到sim卡中。这个就像是一个变量,当移动运营商为它赋值了,它自然就会有值。不赋值自然为空。这就是为什么很多人得不到本机号码的原因。

 

 

 

 

http://archive.cnblogs.com/a/1931248/

http://blog.csdn.net/lifanupc/archive/2010/07/08/5721484.aspx

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics