Last active
March 18, 2020 10:39
-
-
Save Koronaa/9be58adf264dfb4ebfe05c46761756b3 to your computer and use it in GitHub Desktop.
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 static String getPseudoUniqueID() { | |
/* | |
Initially we append all the information with the number "35" so all together we get | |
17 characters and the generatedId starts from 35 which makes it look like a IMEI. | |
But later I commented out DISPLAY,HOST and ID because they can be changed and | |
then the generated ID won't be unique anymore | |
*/ | |
String generatedID = "35" + 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; | |
String serial = null; | |
try { | |
/*Build.serial was exposed to developers in API 9 and some say we can | |
get the serial via reflection for API < 9 */ | |
serial = android.os.Build.class.getField("SERIAL").get(null).toString(); | |
} catch (Exception e) { | |
serial = "serial"; //Can be any value | |
} | |
return new UUID(generatedID.hashCode(), serial.hashCode()).toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment