Example usage for java.util UUID toString

List of usage examples for java.util UUID toString

Introduction

In this page you can find the example usage for java.util UUID toString.

Prototype

public String toString() 

Source Link

Document

Returns a String object representing this UUID .

Usage

From source file:com.github.sebhoss.identifier.service.SuppliedIdentifiers.java

private static String convertUuidToString(final UUID uuid) {
    return uuid.toString().replace("-", ""); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:Main.java

/**
 * get a unique hash of the device.//w ww.ja  v a2s.c om
 * 
 * @return a unique hash of the device.
 */
public static String getDeviceId(Context ctx) {
    if (ctx == null) {
        return null;
    }

    String androidId = "" + android.provider.Settings.Secure.getString(
            ctx.getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
    String deviceName = getDeviceName();

    UUID deviceUuid = new UUID(androidId.hashCode(),
            (long) deviceName.hashCode() << 32 | deviceName.hashCode());
    String deviceId = deviceUuid.toString().replace("-", "");

    return deviceId;
}

From source file:com.njlabs.amrita.aid.util.Identifier.java

@SuppressLint("HardwareIds")
public static String identify(Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

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

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();
}

From source file:Main.java

private static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String tmDevice = null;// ww w.j  a  v a 2 s . com
    String tmSerial = null;
    String androidId = null;
    try {
        tmDevice = tm.getDeviceId();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }
    try {
        tmSerial = tm.getSimSerialNumber();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }
    androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    if (tmDevice == null) {
        tmDevice = "";
    }
    if (tmSerial == null) {
        tmSerial = "";
    }
    if (androidId == null) {
        androidId = "";
    }
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return "lsa-kp" + deviceUuid.toString();
}

From source file:com.mobius.software.mqtt.performance.runner.util.FileUtil.java

public static void logErrors(UUID scenarioID, List<ClientReport> reports) {
    if (reports.isEmpty())
        return;/* w w w  .  j  a  v a  2 s  .c o  m*/

    String filename = DIRECTORY_NAME + File.separator + scenarioID.toString() + LOG_EXTENSION;
    File log = new File(filename);
    if (!log.getParentFile().exists())
        log.getParentFile().mkdir();
    try (PrintWriter pw = new PrintWriter(log)) {
        for (ClientReport clientReport : reports) {
            List<ErrorReport> errorReports = clientReport.getErrors();
            if (!errorReports.isEmpty()) {
                String errorContent = ReportBuilder.buildError(clientReport.getIdentifier(), errorReports);
                pw.println(errorContent);
            }
        }
    } catch (IOException e) {
        logger.error("An error occured while writing error reports to file:" + e.getMessage());
    }

    if (log.length() == 0)
        log.delete();
}

From source file:Main.java

public static String get_device_id(Context ctx) {

    final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

    String tmDevice = "";
    String tmSerial = null;//from  w w w.ja  va2s .c o  m
    String androidId = null;

    try {
        tmDevice = "" + tm.getDeviceId();
    } catch (Exception ex) {
    }

    try {
        tmSerial = "" + tm.getSimSerialNumber();
    } catch (Exception ex) {
    }
    try {
        androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);
    } catch (Exception ex) {
    }
    try {
        UUID deviceUuid = new UUID(androidId.hashCode(),
                ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        String deviceId = deviceUuid.toString();

        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(deviceId.getBytes());

        byte byteData[] = md.digest();

        //convert the byte to hex format method 1
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        deviceId = sb.toString();

        return deviceId;
    } catch (Exception ex) {
    }
    return "nodeviceid";
}

From source file:com.tinypace.mobistore.util.StringUtil.java

public static String GetUuid() {
    UUID uuid = UUID.randomUUID();
    String str = uuid.toString();
    str = str.replace("-", "");
    return str.toUpperCase();
}

From source file:com.baidu.cc.common.SysUtils.java

/**
 * UUID./*from  w w  w .j a v a  2 s  .  c o  m*/
 * 
 * @return UUID 36?
 */
public static String uuid() {
    UUID uuid = UUID.randomUUID();
    return uuid.toString();
}

From source file:Main.java

public static String generateShortUuid() {
    UUID uuid = UUID.randomUUID();
    MessageDigest md = null;/*from ww w .ja  va2s .  c o m*/
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return uuid.toString();
    }

    md.update(uuid.toString().getBytes());
    byte[] digest = md.digest();

    return Base64.encodeToString(digest, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING).substring(0, 20);
}

From source file:com.scf.utils.UUIDUtilies.java

public static String uuid() {
    UUID uuid = UUID.randomUUID();
    return uuid.toString();
}