Last active
December 10, 2017 08:54
-
-
Save VladimirMi/739b10f9b82fb7bd7c99a23e994310a6 to your computer and use it in GitHub Desktop.
DeviceID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String getDeviceId() { | |
String m_szDevIDShort = "35" | |
+ // we make this look like a valid IMEI | |
Build.BOARD.length() % 10 + Build.BRAND.length() % 10 | |
+ Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 | |
+ Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 | |
+ Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 | |
+ Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 | |
+ Build.TAGS.length() % 10 + Build.TYPE.length() % 10 | |
+ Build.USER.length() % 10; // 13 digits | |
String m_szAndroidID = Settings.Secure.getString(App.getInstance().getContentResolver(), Settings.Secure.ANDROID_ID); | |
String m_szLongID = m_szDevIDShort + m_szAndroidID; | |
MessageDigest m = null; | |
try { | |
m = MessageDigest.getInstance("MD5"); | |
} catch (NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
} | |
m.update(m_szLongID.getBytes(), 0, m_szLongID.length()); | |
byte p_md5Data[] = m.digest(); | |
StringBuilder m_szUniqueID = new StringBuilder(); | |
for (byte aP_md5Data : p_md5Data) { | |
int b = (0xFF & aP_md5Data); | |
if (b <= 0xF) | |
m_szUniqueID.append("0"); | |
m_szUniqueID.append(Integer.toHexString(b)); | |
} | |
m_szUniqueID = new StringBuilder(m_szUniqueID.toString().toUpperCase()); | |
return m_szUniqueID.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment