[Code]
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
imei = mTelephonyMgr.getDeviceId();
if (isNull(imei)) {
// 获取MAC
imei = getMac();
// 获取设备号, 恢复出厂设置可能会变
// imei = Secure
// .getString(getContentResolver(), Secure.ANDROID_ID);
}
System.out.println("imei:" + imei);
// 用linux的方法获取设备的唯一号码
// 1,cpu号:
// 文件在: /proc/cpuinfo
// 通过Adb shell 查看:
// adb shell cat /proc/cpuinfo
// 2, mac 地址
// 文件路径 /sys/class/net/wlan0/address
// adb shell cat /sys/class/net/wlan0/address
// 此方法是linux下面获取mac的方法,保证在无wifi情况下也能获取到mac地址
String getMac() {
String macSerial = null;
String str = "";
try {
Process pp = Runtime.getRuntime().exec(
"cat /sys/class/net/wlan0/address ");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (; null != str;) {
str = input.readLine();
if (str != null) {
macSerial = str.trim();// 去空格
break;
}
}
} catch (IOException ex) {
}
return macSerial;
}
[/Code]
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
imei = mTelephonyMgr.getDeviceId();
if (isNull(imei)) {
// 获取MAC
imei = getMac();
// 获取设备号, 恢复出厂设置可能会变
// imei = Secure
// .getString(getContentResolver(), Secure.ANDROID_ID);
}
System.out.println("imei:" + imei);
// 用linux的方法获取设备的唯一号码
// 1,cpu号:
// 文件在: /proc/cpuinfo
// 通过Adb shell 查看:
// adb shell cat /proc/cpuinfo
// 2, mac 地址
// 文件路径 /sys/class/net/wlan0/address
// adb shell cat /sys/class/net/wlan0/address
// 此方法是linux下面获取mac的方法,保证在无wifi情况下也能获取到mac地址
String getMac() {
String macSerial = null;
String str = "";
try {
Process pp = Runtime.getRuntime().exec(
"cat /sys/class/net/wlan0/address ");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (; null != str;) {
str = input.readLine();
if (str != null) {
macSerial = str.trim();// 去空格
break;
}
}
} catch (IOException ex) {
}
return macSerial;
}
[/Code]