2
String androidId = Settings.Secure.getString(getContentResolver(),
                     Settings.Secure.ANDROID_ID);

I'm using this to take android id. Doubt is ANDROID_ID how could be different for signed apk and build apk of same device? I need unique identity of my device. If ANDROID_ID is changed then is it good to use this?

1 Answers1

2

Android 8.0+ randomizes the ANDROID_ID value:

For apps installed on a device running Android 8.0, the value of ANDROID_ID is now scoped per app signing key, as well as per user. The value of ANDROID_ID is unique for each combination of app-signing key, user, and device. As a result, apps with different signing keys running on the same device no longer see the same Android ID (even for the same user).

The documentation has an extensive guide on unique identifiers. Also, be sure to discuss your plans with an attorney.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hello Sir , Is there not any other way to get the Device ID which become unique for the application , please help me on it. – Ravindra Kushwaha Oct 21 '20 at 11:25
  • @RavindraKushwaha: That would appear to be covered in [the documentation that I linked to in the answer](https://developer.android.com/training/articles/user-data-ids). – CommonsWare Oct 21 '20 at 12:29
  • Means i need to use the **READ_PRIVILEGED_PHONE_STATE** permission to get the device id which become same for all applications. @CommonsWare Sir – Ravindra Kushwaha Oct 21 '20 at 12:34
  • @RavindraKushwaha: I do not believe that you need that permission for the Advertising ID or Instance ID mentioned [in the first section of the documentation that I linked to in the answer](https://developer.android.com/training/articles/user-data-ids#best-practices-android-identifiers). – CommonsWare Oct 21 '20 at 12:36
  • For the Advertising ID i need to implement the AD-MOB and for Instance ID which thing i need to implement, any example please @CommonsWare sir – Ravindra Kushwaha Oct 21 '20 at 12:38
  • @RavindraKushwaha: https://stackoverflow.com/a/51125384/115145 – CommonsWare Oct 21 '20 at 12:43
  • Thanks Sir but it may vary from application to application. – Ravindra Kushwaha Oct 21 '20 at 12:46
  • @RavindraKushwaha: Well, yes. Your original comment asked for an identifier "which become unique for the application". – CommonsWare Oct 21 '20 at 12:47
  • Sir , Last question, Its not possible to get unique id which become same for all the applications ? – Ravindra Kushwaha Oct 21 '20 at 12:55
  • @RavindraKushwaha: I hope that is no longer possible, for privacy reasons. – CommonsWare Oct 21 '20 at 12:56