Android如何区别真机和模拟器

一,native方式。

通过c代码读取设备中的配置和硬件相关信息。

 

1,diskstats

获取闪存的分区状态信息。

int fd = open(“/proc/diskstats”, O_RDONLY);

bytes = read(fd, buf, bytes);

区别:真机下都有mmcblk0分区,但是模拟器没有分区信息。

 

2,mac地址。

通过socket和ioctl读取mac地址。

sockfd = socket(AF_INET, SOCK_DGRAM, 0);

ioctl(sockfd, SIOCGIFCONF, (char*)&ifc);

ioctl(sockfd, SIOCGIFADDR, &ifr[i])

ioctl(sockfd, SIOCGIFHWADDR, (char*)&ifr[i])

 

区别:真机可以获取wlan0的ip和mac地址,模拟器只能获取eth0的ip和mac地址;

 

3,有用的prop信息。

__system_property_get(key, buf);

区别: 模拟器没有ro.boot.serialno和ro.serialno属性,真机中为机器序列号。

模拟器 ro.hardware属性为goldfish,真机为各自的型号。

 

4,cpu信息。

int fd = open(“/proc/cpuinfo”, O_RDONLY);

bytes = read(fd, buf, bytes);

区别:模拟器中cpuinfo的硬件为Goldfish。

 

5,drivers

int fd = open(“/proc/tty/drivers”, O_RDONLY);

区别:模拟器中包含goldfish的驱动

 

6,模拟器特有文件。

int fd = open(“/dev/socket/qemud”, O_RDONLY);

int fd = open(“/dev/qemu_pipe”, O_RDONLY);

区别:模拟器专有的文件,真机中没有。

 

二,传统的方式:

通过Java层的代码获取,可以有以下方式:

 

1,IMEI和IMSI

IMEI  移动设备国际身份码。

IMSI  IMSI国际移动用户识别码,储存在SIM卡中

final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

String imei = tm.getDeviceId();

String imsi = tm.getSubscriberId();

 

设备1:354273055927169 / null(无卡)

设备2:862966024243759 / 460011040618938

模拟器:000000000000000 / 310260000000000

 

2,Serial序列号

String serial = android.os.Build.SERIAL;

 

设备1:4df78680771b117b

设备2:OBAI5HDQZPDIRCQG

模拟器:unknown

 

3,android_id

String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

设备和模拟器都有,16位。

 

4,Mac地址

WifiManager wifimanage=(WifiManager)getSystemService(Context.WIFI_SERVICE);  WifiInfo wifiinfo= wifimanage.getConnectionInfo();

设备1:88:32:9b:1e:49:20

设备2:f8:a4:5f:fd:56:17

模拟器:null

转载于:https://www.cnblogs.com/yxfcnbg/p/4918020.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值