Android 获取手机信息

本文介绍如何在Android开发中使用TelephonyManager获取本机电话号码及通过Build类获取设备型号和其他硬件信息的方法。同时强调了权限配置的重要性。
 

Android开发平台中,可通过TelephonyManager 获取本机号码。

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

  2. txtPhoneNumber.setText(phoneMgr.getLine1Number()); //txtPhoneNumber是一个EditText 用于显示手机号

注:根据Android的安全机制,在使用TelephonyManager时,必须在AndroidManifest.xml中添加<uses-permission android:name="READ_PHONE_STATE" /> 否则无法获得系统的许可。


  手机型号 Build.MODEL

  1. private void loadPhoneStatus(){

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

  3. txtPhoneModel.setText(Build.MODEL); //手机型号
  4. txtPhoneNumber.setText(phoneMgr.getLine1Number());//本机电话号码
  5. txtSdkVersion.setText(Build.VERSION.SDK);//SDK版本号
  6. txtOsVersion.setText(Build.VERSION.RELEASE);//Firmware/OS 版本号
  7. }

  事实上,Build能向我们提供包括 硬件厂商,硬件编号,序列号等很多信息 调用方法也都同上,下面是Build中的API中定义。

public          static          final          StringBOARDThe name of the underlying board, like "goldfish".
          public          static          final          StringBOOTLOADERThe system bootloader version number.
          public          static          final          StringBRANDThe brand (e.g., carrier) the software is customized for, if any.
          public          static          final          StringCPU_ABIThe name of the instruction set (CPU type + ABI convention) of native code.
          public          static          final          StringCPU_ABI2The name of the second instruction set (CPU type + ABI convention) of native code.
          public          static          final          StringDEVICEThe name of the industrial design.
          public          static          final          StringDISPLAYA build ID string meant for displaying to the user
          public          static          final          StringFINGERPRINTA string that uniquely identifies this build.
          public          static          final          StringHARDWAREThe name of the hardware (from the kernel command line or /proc).
          public          static          final          StringHOST 
          public          static          final          StringIDEither a changelist number, or a label like "M4-rc20".
          public          static          final          StringMANUFACTURERThe manufacturer of the product/hardware.
          public          static          final          StringMODELThe end-user-visible name for the end product.
          public          static          final          StringPRODUCTThe name of the overall product.
          public          static          final          StringRADIOThe radio firmware version number.
          public          static          final          StringSERIALA hardware serial number, if available.
          public          static          final          StringTAGSComma-separated tags describing the build, like "unsigned,debug".
          public          static          final          longTIME 
          public          static          final          StringTYPEThe type of build, like "user" or "eng".
          public          static          final          StringUSER 


效果图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值