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

This question already has an answer here:

  • Is there a unique Android device ID? 40 answers

  • 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


    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);
    }
    

    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:

  • 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.
  • You can generate a unique key per device yourself (using something like a UUID) and store it on the device (shared prefs, file, database...).
  • 链接地址: http://www.djcxy.com/p/24656.html

    上一篇: 所有Android设备上都可以使用IMEI吗? 它可以不被篡改吗?

    下一篇: Android:在App更新中更改Android ID。 一些独特的东西呢?