Example usage for android.telephony TelephonyManager getDeviceId

List of usage examples for android.telephony TelephonyManager getDeviceId

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getDeviceId.

Prototype

@Deprecated
@SuppressAutoDoc 
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceId() 

Source Link

Document

Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.

Usage

From source file:Main.java

/**
 * Returns the IMEI Number./*from w w  w .  ja v  a 2s  .c o  m*/
 * @return - Device IMEI number.
 */
public static String getDeviceId(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = telephonyManager.getDeviceId();

    if (deviceId == null || deviceId.isEmpty()) {
        deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    }

    return deviceId;
}

From source file:Main.java

public static final String getDeviceCode(Context context) {
    TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telManager != null) {
        return telManager.getDeviceId();
    }/* w w  w  . ja  v a  2  s . c o  m*/
    return getLocalMacAddress(context);
}

From source file:Main.java

public static String getImei(Context context, String imei) {
    try {// w w  w  .  j ava 2 s .  c  om
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        imei = telephonyManager.getDeviceId();
    } catch (Exception e) {
    }
    return imei;
}

From source file:Main.java

public static String getDeviceId(Context context) {
    try {/*  ww  w  .j a  va2 s. c  o  m*/
        TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String szImei = TelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE
        return szImei;
    } catch (Exception e) {
        // Oh well
    }
    try {
        String m_szDevIDShort = "35" + //we make this look like a valid IMEI
                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
        return m_szDevIDShort;
    } catch (Exception e) {
        // Oh well
    }
    return "tempid" + getRandom().nextInt();
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        return telephonyManager.getDeviceId();
    }//from   ww  w. java 2 s .  com

    return "";

}

From source file:Main.java

public static String getDeviceIMEI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null || TextUtils.isEmpty(telephonyManager.getDeviceId())) {
        return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    } else {//w w  w . ja va2s.c  o  m
        return telephonyManager.getDeviceId();
    }
}

From source file:Main.java

/**
 * Get unique device info.//from  ww  w  . ja v  a 2  s .  c o m
 *
 * @param context application context.
 * @return returns a json object of the device, manufacturer, build version, and a unique id.
 */
public static JSONObject getDeviceInfo(Context context) {
    JSONObject deviceInfo = new JSONObject();
    try {
        deviceInfo.put("device", Build.MODEL);
        deviceInfo.put("manufacturer", Build.MANUFACTURER);
        deviceInfo.put("android", android.os.Build.VERSION.SDK);

        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        String tmDevice = tm.getDeviceId();
        String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
        String serial = null;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO)
            serial = Build.SERIAL;
        if (androidId != null)
            deviceInfo.put("uid", androidId);
        else if (serial != null)
            deviceInfo.put("uid", serial);
        else if (tmDevice != null)
            deviceInfo.put("uid", tmDevice);
        deviceInfo.put("carrier", tm.getNetworkOperatorName());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return deviceInfo;
}

From source file:Main.java

private static String getPhoneIMEI(Context context) {
    String result = null;/*  ww w  .  j  a v a  2  s  .c  om*/
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        result = tm.getDeviceId();
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }

    return result == null ? "" : result;
}

From source file:Main.java

public static String getImeiNo(Context context) {
    TelephonyManager TelephonyMgr = null;
    try {//  www .j a v a  2  s  . c  o m
        TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return TelephonyMgr.getDeviceId();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * get IMEI//  w w  w.  j  a  v a2 s . co m
 * 
 * @return
 */
public static String getIMEI(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return null;
    }
    return tm.getDeviceId();
}