android 手机信息获取

来源:互联网 发布:飞凡网络 编辑:程序博客网 时间:2024/05/16 11:40

原文地址: http://www.cocos2dev.com/?p=208

今天要获取用户反馈意见,我默认将用户的手机号码上传了,结果发现并不是所有的手机能拿到本机号码。找了下发现原是用户的SIM卡没有写入本机号码导致的。

Android获取本机号码:

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

String phoneNum = phoneMgr.getLine1Number(); 

AndroidManifest.xml中添加权限:

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

刚才也说了,手机号码不是所有的都能获取。只是有一部分可以拿到。这个是由于移动运营商没有把手机号码的数据写入到sim卡中。

手机型号 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 getPhoneStatus(){

TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);      
String model = Build.MODEL; //手机型号
String phoneNum = phoneMgr.getLine1Number();//本机电话号码
String sdkVersion = Build.VERSION.SDK;//SDK版本号
String osVersion = Build.VERSION.RELEASE;//Firmware/OS 版本号
}

Build中包括 硬件厂商,硬件编号,序列号等很多信息。调用方法也很简单,和上面类似的。

下面是Google提供的参考表:

StringBOARDThe name of the underlying board, like "goldfish". (底层董事会名称)StringBOOTLOADERThe system bootloader version number.StringBRANDThe brand (e.g., carrier) the software is customized for, if any.(定制的系统的商标)StringCPU_ABIThe name of the instruction set (CPU type + ABI convention) of native code.StringCPU_ABI2The name of the second instruction set (CPU type + ABI convention) of native code.StringDEVICEThe name of the industrial design.(工业设计者名称,同board)StringDISPLAYA build ID string meant for displaying to the user(显示给用户的 (版本号)ID+INCREMENTAL)StringFINGERPRINTA string that uniquely identifies this build.(手机唯一性标示,包含所有信息)StringHARDWAREThe name of the hardware (from the kernel command line or /proc).StringHOST(管理员名称)StringIDEither a changelist number, or a label like "M4-rc20".(like MIUI,即版本号前缀)StringMANUFACTURERThe manufacturer of the product/hardware.(手机厂商)StringMODELThe end-user-visible name for the end product.  (手机型号)StringPRODUCTThe name of the overall product.    (产品总体名称型号)StringRADIOThe radio firmware version number.StringSERIALA hardware serial number, if available.StringTAGSComma-separated tags describing the build, like "unsigned,debug".longTIME StringTYPEThe type of build, like "user" or "eng".StringUNKNOWNValue used for when a build property is unknown.StringUSER