其他分享
首页 > 其他分享> > 如何在Android中获得持久的udid?

如何在Android中获得持久的udid?

作者:互联网

我正在开发一个社交媒体应用程序,我想为每个注册到我的服务器的设备生成一个唯一的编号.我的问题是,如何生成一个不会改变的udid.例如,用户卸载应用程序而不是再次安装它(激活udid生成)它必须与卸载之前相同.此外,udid必须采用以下格式:

c376e418-da42-39fb-0000-d821f1fd2804

请分享任何想法!先感谢您!

解决方法:

您可以使用检查以下代码来生成唯一的udid.

 TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId;
if (telephonyManager.getDeviceId() != null)
    deviceId = telephonyManager.getDeviceId(); //*** use for mobiles
else {
    deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
}
return deviceId;

标签:android,udid
来源: https://codeday.me/bug/20190727/1556272.html