Android UUID生成(IMEI、设备序列号、MAC地址)
根据手机设备的IMEI、设备序列号、MAC地址经过MD5加密,得到手机专有的序号;
import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.telephony.TelephonyManager; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Formatter; public class Utils { public Utils() { } public static final String generateUUID(Context context) { String s = ((TelephonyManager)context.getSystemService("phone")).getDeviceId(); if(s == null) s = ""; String s1 = android.provider.Settings.Secure.getString(context.getContentResolver(), "android_id"); if(s1 == null) s1 = ""; String s2; String s3; WifiInfo wifiinfo; String s4; if(android.os.Build.VERSION.SDK_INT >= 9) { s2 = Build.SERIAL; if(s2 == null) s2 = ""; } else { s2 = getDeviceSerial(); } s3 = ""; wifiinfo = ((WifiManager)context.getSystemService("wifi")).getConnectionInfo(); if(wifiinfo != null) { s3 = wifiinfo.getMacAddress(); if(s3 == null) s3 = ""; } try { s4 = getMD5String((new StringBuilder()).append(s).append(s1).append(s2).append(s3).toString()); } catch(NoSuchAlgorithmException nosuchalgorithmexception) { nosuchalgorithmexception.printStackTrace(); return null; } return s4; } private static final String getDeviceSerial() { String s; try { Method method = Class.forName("android.os.Build").getDeclaredMethod("getString", new Class[] { Class.forName("java.lang.String") }); if(!method.isAccessible()) method.setAccessible(true); s = (String)method.invoke(new Build(), new Object[] { "ro.serialno" }); } catch(ClassNotFoundException classnotfoundexception) { classnotfoundexception.printStackTrace(); return ""; } catch(NoSuchMethodException nosuchmethodexception) { nosuchmethodexception.printStackTrace(); return ""; } catch(InvocationTargetException invocationtargetexception) { invocationtargetexception.printStackTrace(); return ""; } catch(IllegalAccessException illegalaccessexception) { illegalaccessexception.printStackTrace(); return ""; } return s; } private static final String getMD5String(String s) throws NoSuchAlgorithmException { byte abyte0[] = MessageDigest.getInstance("SHA-1").digest(s.getBytes()); Formatter formatter = new Formatter(); int i = abyte0.length; for(int j = 0; j < i; j++) { byte byte0 = abyte0[j]; Object aobj[] = new Object[1]; aobj[0] = Byte.valueOf(byte0); formatter.format("%02x", aobj); } return formatter.toString(); } }
本段代码反编译而得
分类:
android 工具类
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!