Return pseudo unique ID - Android Hardware

Android examples for Hardware:Device ID

Description

Return pseudo unique ID

Demo Code


//package com.java2s;

import android.os.Build;

import java.util.UUID;

public class Main {
    /**/*from   w w  w  .j  a v a 2 s.  c om*/
     * Return pseudo unique ID
     * @return ID
     */
    public static String getUniquePsuedoID() {

        String m_szDevIDShort = "35" + (Build.BOARD.length() % 10)
                + (Build.BRAND.length() % 10)
                + (Build.CPU_ABI.length() % 10)
                + (Build.DEVICE.length() % 10)
                + (Build.MANUFACTURER.length() % 10)
                + (Build.MODEL.length() % 10)
                + (Build.PRODUCT.length() % 10);

        String serial = null;
        try {
            serial = android.os.Build.class.getField("SERIAL").get(null)
                    .toString();
            return new UUID(m_szDevIDShort.hashCode(), serial.hashCode())
                    .toString();
        } catch (Exception exception) {
            // String needs to be initialized
            serial = "serial"; // some value
        }

        return new UUID(m_szDevIDShort.hashCode(), serial.hashCode())
                .toString();
    }
}

Related Tutorials