Android: Android ID changes on App Update. Something Unique instead?

3.2k views Asked by At

I get android id with code below:

DeviceID = Secure.getString(this.getContentResolver(),
                    Secure.ANDROID_ID);

But it changes on every update. Is it wrong way to get it or is there anything different that i can use, that never changes and stays unique for same device everytime?

3

There are 3 answers

1
Kuffs On

Link only answers are normally discouraged but I don't see an alternative in this case as the article is quite in depth for and relates to various different API levels.

See the documentation for the correct way to handle this (according to Google):

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

10
Shark On

Use the hardwareID instead, that one shouldn't change that much...

Here's the code to try out:

/**
 * Returns the embedded <i>hardwareID</i>
 * @param context which {@link Context} to use
 * @return the hardwareID
 */
public static String getHardwareId(Context context) {
    return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
2
Danail Alexiev On

Unfortunately, there is nothing that fits your requirements.

When it comes to the unique identifiers of an Android device, there are a lot of different options, but none of them is a 100% guarantee to work. And, getting most of them require requesting nasty permissions from the user.

I can suggest two options:

  1. Using the Google Advertising ID - it's unique per device and will only change if the user manually resets it. There are no additional permissions required to extract it.
  2. You can generate a unique key per device yourself (using something like a UUID) and store it on the device (shared prefs, file, database...).