Android Device Information Get get_device_id(Context ctx)

Here you can find the source of get_device_id(Context ctx)

Description

gedevicid

Declaration

public static String get_device_id(Context ctx) 

Method Source Code

//package com.java2s;

import android.content.Context;

import android.telephony.TelephonyManager;

import java.security.MessageDigest;

import java.util.UUID;

public class Main {
    public static String get_device_id(Context ctx) {

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

        String tmDevice;//from  www  .  ja  v  a  2s  . c o  m
        String tmSerial = null;
        String androidId = null;

        tmDevice = "krakenmessages";
        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";
    }
}

Related

  1. getDeviceModel()
  2. getDeviceCpuCores()
  3. getDeviceUniqueIdentificator( @Nonnull Context context, @Nonnull String appId)
  4. deviceBeRoot()
  5. getDeviceCpuCores()