Android如何区别真机和模拟器
2015-10-28 17:33
567 查看
一,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
通过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
相关文章推荐
- 获取第三方apk的资源文件
- android常识
- Android 获取手机联系人代码
- 安卓开发学习之010 TableLayout详解+计算器实现
- Android笔记—Intent传递序列化HashMap对象
- 常用开源镜像站整理android sdk manager
- 关于Android游戏开发的资料
- android 工程lib 里的目录和文件
- 推荐几个Android开发非常有用的工具(for android studio)
- Android实战技巧之四十二:加速度传感器
- android上加载大图片需要注意的问题
- Android:背景渐变色
- Android 各种Adapter
- 屏幕适配的选择
- MP4文件格式的解析,以及MP4文件的分割算法
- Android如何判断一个应用在运行
- 【FastDev4Android框架开发】AndroidAnnnotations注入框架的工作原理(八)
- Android APK反编译
- Android Studio的相关错误
- Android初学习 - Notification的使用方法