您从 Android 获得的 UniqueId 有时会改变吗?

Does the UniqueId you get from Android change sometime?

经过大量阅读和记录后,我很清楚 Android 10 无法再获取 IMEI。

我用它 (IMEI) 来确定哪个用户拥有哪个 phone,因此在登录中进行了验证,这样用户就不会从不属于的 phone 开始his assigned, now as I read an option is to use the UniqueID, or I don't know what others are options, but how much do these Ids change? 是的,我读到一个选项是使用UniqueID,或者我不知道其他人会有什么选项,但是这些Ids改变了多少?每次 OS 更新? android 的新大版本?或者他们永远不会改变?

我的实际代码:

 if (IMEIValue == null)
        IMEIValue = getUniqueID();

请提供代码示例。

谢谢!

private static String uniqueID = null;
private static final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
public synchronized static String id(Context context) {
   if (uniqueID == null) {
      SharedPreferences sharedPrefs = context.getSharedPreferences(
         PREF_UNIQUE_ID, Context.MODE_PRIVATE);
      uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null);
      if (uniqueID == null) {
         uniqueID = UUID.randomUUID().toString();
         Editor editor = sharedPrefs.edit();
         editor.putString(PREF_UNIQUE_ID, uniqueID);
         editor.commit();
      }
   }
    return uniqueID;
}

UUID.randomUUID() method generates an unique identifier for a specific installation. You have just to store that value and your user will be identified at the next launch of your application.

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

p.s。希望我能回答你的问题或至少以某种方式给出提示 :)