简体   繁体   English

在Android中获取唯一的设备ID

[英]Get unique device ID in android

I would like to know how to get a String that uniquely identify the current device in android. 我想知道如何获取一个字符串,该字符串可唯一标识android中的当前设备。 I know this has been asked before but all the answers are the same: to use the ANDROID_ID constant. 我知道这已经被问过了,但是所有答案都是相同的:使用ANDROID_ID常量。 The thing is that it is deprecated and also insecure. 事实是,它已被弃用并且也不安全。 Is there any other possibility? 还有其他可能性吗?

Thanks. 谢谢。

There is no ideal way. 没有理想的方法。 Best way is to generate one on your own and then reuse it till app is installed. 最好的方法是自己生成一个,然后重复使用直到安装应用程序。 You can use 您可以使用

 String uniqueId = UUID.randomUUID().toString(); 

Generate it the first time the app launches and save it in your shared preference for further use.. This will change after every new installation and hence you can track app installations as well. 首次启动应用程序时生成它,并将其保存在共享首选项中,以备将来使用。每安装一次新应用程序,它就会发生变化,因此您也可以跟踪应用程序安装。

See the following post which describe the several ways to retrieve an Unique ID to identify Android devices.. 请参阅以下文章,其中描述了检索唯一ID以标识Android设备的几种方法。

https://medium.com/@ssaurel/how-to-retrieve-an-unique-id-to-identify-android-devices-c40080e04fa4 https://medium.com/@ssaurel/how-to-retrieve-an-unique-id-to-identify-android-devices-c40080e04fa4

and refer to Android Developers Best Practices for Unique Identifiers to know which are recommended and which are not.. 并参考Android开发者唯一标识符最佳做法,以了解哪些是推荐的,哪些不是。

https://developer.android.com/training/articles/user-data-ids.html https://developer.android.com/training/articles/user-data-ids.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM