Android 获得设备状态信息、Mac地址、IP地址

本文介绍了在Android开发中如何获取设备状态信息,包括通过Build获取硬件信息,使用getSystemService获取IP地址,以及获取Mac地址和IMEI码的方法。同时提到了所需的权限和相关系统服务。
摘要由CSDN通过智能技术生成

前言

在APP开发时,经常会遇到要获取手机状态信息的场景,像升级时获取版本号,像发生异常时要收集手机信息等等。有些软件还要根据Mac地址来判定当前用户以前是否登录过。下面将一一介绍获取这些手机状态信息的方法。

1 通过build获取手机硬件信息

  • 运用反射获取Build信息,然后从build中得到对应字段的值。这种情况适用于获取所有的build信息。
  • 或者直接调用Build类直接拿里面的字段名,如:android.os.Build.MODEL; // 手机型号 。这是为了获取单独某个手机信息的方法,直接调用Build的字段即可拿到对应信息,简单快捷。
  • 别忘了加权限
 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

下面是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.品牌型号名,如小米4对应cancro
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 
  • 6
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值