当前位置: 代码迷 >> Android >> android装置获取设备唯一号
  详细解决方案

android装置获取设备唯一号

热度:87   发布时间:2016-04-28 05:07:31.0
android设备获取设备唯一号
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;}
  相关解决方案