hienlt0610
3/20/2020 - 9:48 AM

[Java] PseudoUniqueID.java

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();

}