/* 获取设备唯一标识码 mac */
public static String getDeviceId(Context context) {
StringBuilder deviceId = new StringBuilder();
// 渠道标志
deviceId.append("a");
try {
//wifi mac地址
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String wifiMac = info.getMacAddress();
if(!wifiMac.equals(null)){
deviceId.append("wifi");
deviceId.append(wifiMac);
Log.i("getDeviceId : ", deviceId.toString());
return deviceId.toString();
}
//IMEI(imei)
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
if(!imei.equals(null)){
deviceId.append("imei");
deviceId.append(imei);
Log.i("getDeviceId : ", deviceId.toString());
return deviceId.toString();
}
//序列号(sn)
String sn = tm.getSimSerialNumber();
if(!sn.equals(null)){
deviceId.append("sn");
deviceId.append(sn);
Log.i("getDeviceId : ", deviceId.toString());
return deviceId.toString();
}
//如果上面都没有, 则生成一个id:随机码
// String uuid = getUUID(context);
// if(!isEmpty(uuid)){
// deviceId.append("id");
// deviceId.append(uuid);
// Log.e("getDeviceId : ", deviceId.toString());
// return deviceId.toString();
// }
} catch (Exception e) {
e.printStackTrace();
//deviceId.append("id").append(getUUID(context));
}
Log.i("getDeviceId : ", deviceId.toString());
return deviceId.toString();
}
android 获取手机的唯一标识符
最新推荐文章于 2024-09-07 08:39:53 发布