get Device Unique Code - Android Hardware

Android examples for Hardware:Device Feature

Description

get Device Unique Code

Demo Code


//package com.java2s;

import android.content.Context;

import android.os.Build;
import android.telephony.TelephonyManager;

public class Main {

    public static String getDeviceUniqueCode(Context ctx) {
        TelephonyManager tm = (TelephonyManager) ctx
                .getSystemService(Context.TELEPHONY_SERVICE);
        String uniqueCode = tm.getDeviceId();
        if (uniqueCode == null || uniqueCode.length() <= 10) {
            uniqueCode = "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; //13 digits  
        }/*from   w w w .  j  a va 2s .  c  om*/
        return uniqueCode;
    }
}

Related Tutorials