Android 唯一设备号生成方案
来源:互联网 发布:链轮设计软件 编辑:程序博客网 时间:2024/06/07 00:01
以下是一种比较靠谱的解决方案。通过获取到 IMEI、AndroidId、macAddress 进行拼接,再将拼接结果进行 MD5 转换,那么就可以得到一串 32 个字符的 16 进制数据,这时候也能够保证得到的设备唯一标识为统一的长度。这样也能够很大程度上保证你最终得到的唯一标识不为空,因为这三个值同时为空几乎不大可能。
public static String generateUniqueDeviceId(){ Context context = MyApplication.getInstance(); String imei = ""; String androidId = ""; String macAddress = ""; TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE); if (telephonyManager != null) { imei = telephonyManager.getDeviceId(); } ContentResolver contentResolver = context.getContentResolver(); if (contentResolver != null) { androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID); } WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { macAddress = wifiManager.getConnectionInfo().getMacAddress(); } StringBuilder longIdBuilder = new StringBuilder(); if (imei != null) { longIdBuilder.append(imei); } if (androidId != null) { longIdBuilder.append(androidId); } if (macAddress != null) { longIdBuilder.append(macAddress); } return MD5Utils.toMd5(longIdBuilder.toString()); }
获取 IMEI 需要加入权限 android.permission.READ_PHONE_STATE
获取 macAddress 需要加入权限 android.permission.ACCESS_WIFI_STATE
0 0
- Android 唯一设备号生成方案
- android唯一机器码生成方案
- Android唯一标识生成方案
- Android唯一识别号(设备指纹)的生成
- Android 设备唯一标识生成方式
- Android 设备唯一标识生成方式
- Android获取唯一设备号
- 获取Android唯一设备号
- 获取Android设备唯一号
- Android唯一识别号(设备指纹)的生成及原理
- 手机唯一标识生成方案
- 全局唯一ID生成方案
- 数据库唯一序列号生成方案
- Android获得手机唯一设备ID号
- Android获得手机唯一设备ID号
- android 设备唯一编码
- android设备唯一标识
- android 设备唯一码
- swust.oj.1075
- 飞翔nyoj195
- Lightoj1111——Best Picnic Ever(dfs)
- linux动态库及静态库的制作和makefile的简单编写
- [LintCode]Maximum Subarray III
- Android 唯一设备号生成方案
- 机器学习中各种距离
- 事件的绑定与解绑
- JNI学习积累之一 ---- 常用函数大全
- 重启docker服务器后 遇到 'device or resource busy'错误
- 直接插入排序
- 结构体嵌套二级指针
- UVALive 4287 Proving Equivalences(强连通分量)
- Friends number (数论,打表)