Skip to content Skip to sidebar Skip to footer

Android And Java Uuid

I want to generate a uuid for my app i tried many things like wifi mac address , getting android id, serial number , creating pseudo uuid from device android.os.Build properties .

Solution 1:

Assuming you're using the java.util.UUID's randomUUID() function there's a theoretical chance of duplication, but it's incredibly remote. The ids generated are RFC4122 version-4 ids, which have 122 bits randomly set. That means there are 5.32 x 10^^36 possible values. For some perspective on that, if you had a billion devices, each generating a billion IDs per second, it would take roughly 168 billion years for them to finish (~10X the age of the universe).

So, yes, duplication is possible, but (assuming Java is using a high quality random number generator), the odds of it actually happening are so remote as to be meaningless.


Solution 2:

to Get Device ID Use Telephoney U can use it here is it is

public static String deviceUDID(Context ctx) {
     final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

     final String tmDevice, tmSerial, androidId;
     tmDevice = "" + tm.getDeviceId();
     tmSerial = "" + tm.getSimSerialNumber();
     androidId = "" +android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

     UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
     String deviceId = deviceUuid.toString();
     Log.d("Device Id", deviceId);
     return deviceId;
} 

Post a Comment for "Android And Java Uuid"