The Tokenizer
The Tokenizer

Reputation: 1564

Application Generate UUID?

I guess i kind of need more understand of how a UUID actually works. Im working on an application and i want the app to generate a UUID the first time the user downloads and runs the app. Is it possible to generate a new uuid each time a user downloads an app?

http://developer.android.com/reference/java/util/UUID.html and maybe if there is another site other than android developer where i can understand or see examples of sombody using a uuid, can sombody post? Thank You.

Upvotes: 3

Views: 7344

Answers (2)

Marc Davies
Marc Davies

Reputation: 215

UUID uuid = UUID.randomUUID();

This should generate you a random UUID for you to use how ever you wish.

Upvotes: 13

Hiren Dabhi
Hiren Dabhi

Reputation: 3713

Here is the code to generate UUID :

String android_id = Secure.getString(getApplicationContext()
            .getContentResolver(), Secure.ANDROID_ID);
    Log.i("System out", "android_id : " + android_id);

    final TelephonyManager tm = (TelephonyManager) getBaseContext()
            .getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    Log.i("System out", "tmDevice : " + tmDevice);
    tmSerial = "" + tm.getSimSerialNumber();
    Log.i("System out", "tmSerial : " + tmSerial);
    androidId = ""
            + android.provider.Settings.Secure.getString(
                    getContentResolver(),
                    android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice
            .hashCode() << 32)
            | tmSerial.hashCode());
    String UUID = deviceUuid.toString();
    Log.i("System out", "UUID : " + UUID);

Upvotes: 4

Related Questions