0

I would like to know how to get a String that uniquely identify the current device in android. I know this has been asked before but all the answers are the same: to use the ANDROID_ID constant. The thing is that it is deprecated and also insecure. Is there any other possibility?

Thanks.

Jaime Alcántara Arnela
  • 2,062
  • 5
  • 25
  • 56
  • In which environment/language? – nageeb Jul 26 '17 at 15:41
  • 1
    It doesn't seems deprecated... https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID – litelite Jul 26 '17 at 15:41
  • 2
    You need to consider whether you want 1) an ID uniquely and forever tied to that particular piece of hardware; 2) an ID that is reset by factory reset (so you can sell your phone to someone without selling them your identity; 3) an ID that is tied to your phone plan so you can swap SIM cards and interact with a new carrier as a new person. 4) an ID associated with a particular installation of a particular app. 5) etc.' – Dale Wilson Jul 26 '17 at 15:42
  • It's very important to indicate the reason you want the ID for. do you want it to persist after reinstall of the application ? what about factory reset? or maybe you don't care both? – ApriOri Jul 26 '17 at 15:57

2 Answers2

1

See the following post which describe the several ways to retrieve an Unique ID to identify Android devices..

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..

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

Shareefoo
  • 41
  • 2
  • 1
    This would be a good answer if it didn't depend on links to external sites which may not be valid in the future. Consider quoting some of the content of the pages you link to so this page will remain valid even if the links decay. – Dale Wilson Jul 26 '17 at 15:46
  • @DaleWilson thank you dale for your suggestion, i really wanted to put the real talk here but there are many ways and many perspectives to describe and i thought developer.android links will never be invalid so there's that. – Shareefoo Jul 26 '17 at 15:52
0

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.

Kapil G
  • 4,081
  • 2
  • 20
  • 32
  • `UUID.randomUUID()` does not give unique id. It gives random value everytime. – Sagar Chapagain Jul 26 '17 at 15:44
  • Exactly and hence to be generated at the first open of app. – Kapil G Jul 26 '17 at 15:45
  • 1
    I used same for the primary key in realm database. But I don't think it is wise to use it as unique device id. Since it cannot be obtained later after uninstalling and reinstalling the app. So it cannot work as unique device id. – Sagar Chapagain Jul 26 '17 at 16:04
  • @SagarChapagain Usually tracking user's device is ideally not necessary in most of the scenarios. Plus its a privacy violation already in iOS and the app will get rejected and even Android is moving towards that as well so might not be future proof. – Kapil G Jul 26 '17 at 16:17