androidudid

How to get a persistent udid in Android?


I am developing a social media app and I want to generate a unique number for every device that registers to my server. My question is, how to generate a udid that won't change in the furure.

For example, the user uninstall the app and than install it again (udid generation activated) it has to be the same one that was before the uninstall. Also, the udid has to be in the following format:

c376e418-da42-39fb-0000-d821f1fd2804

Please share any ideas!


Solution

  • You can use check following code to to generate unique udid.

     TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId;
    if (telephonyManager.getDeviceId() != null)
        deviceId = telephonyManager.getDeviceId(); //*** use for mobiles
    else {
        deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    }
    return deviceId;