Skip to content

Instantly share code, notes, and snippets.

@MaxGraey
Last active March 15, 2018 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxGraey/28972b6bbd3192c80eb5638de049d42a to your computer and use it in GitHub Desktop.
Save MaxGraey/28972b6bbd3192c80eb5638de049d42a to your computer and use it in GitHub Desktop.
android UUID
private static extern(Android) string GetUUID()
@{
//android.app.Activity context = com.fuse.Activity.getRootActivity();
//return android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
final android.app.Activity context = com.fuse.Activity.getRootActivity();
final TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
final String deviceId = "" + tm.getDeviceId();
final String serialNum = "" + tm.getSimSerialNumber();
final String androidId = "" + android.provider.Settings.Secure.getString(
context.getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID
);
int macAdressId = 0x7FFFFFFF;
try {
final InetAddress ip = InetAddress.getLocalHost();
final NetworkInterface network = NetworkInterface.getByInetAddress(ip);
macAdressId = network.getHardwareAddress().hashCode();
} catch (Throwable e) {}
//UUID deviceUuid = new UUID((((long)macAdressId << 32) + androidId.hashCode()),
// ((long)deviceId.hashCode() << 32) + serialNum.hashCode());
long first = ((long)macAdressId << 32) + androidId.hashCode();
long second = ((long)deviceId.hashCode() << 32) + serialNum.hashCode();
byte[] bytes = ByteBuffer.allocate(2 * Long.SIZE / Byte.SIZE)
.putLong(first)
.putLong(second)
.array();
int[] hashedUUID = md5.encode128(bytes);
first = (long)hashedUUID[0] | (long)hashedUUID[1] << 32;
second = (long)hashedUUID[2] | (long)hashedUUID[3] << 32;
return new UUID(first, second).toString().toUpperCase();
@}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment