I don't know why (specifically) you're using an unique id, but in my case I use it to identify a unique "app instalation". So it's not dependent of simCards, telephonymanager and etc.
What I did was create a unique id (when it has not been created yet) and stored it in sharedprefs:
private static String uniqueID = null;
public static String getDeviceUniqueID(Context context)
{
if (uniqueID == null)
{
final String PREF_UNIQUE_ID = "PREF_UNIQUE_ID";
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;
}
Caveats:
- Of course it will be lost when user uninstalls the app, because sharedprefs are deleted too;
- There's a chance of a unique id to be generated for 2 different users (but are trillions or more per one).
But, as I said above: "don't know why you're using it".
It works like a charm to me this way. Perhaps it'll work for you too. Cheers.