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

/***
 * getIMEI : read the IMEI number of device The IMEI (14 decimal digits plus
 * a check digit) or IMEISV (16 digits) includes information on the origin,
 * model, and serial number of the device. The structure of the IMEI/SV are
 * specified in 3GPP TS 23.003/*from  w w w.  j  av  a2s .com*/
 * 
 * @param activity
 * @return 16 digit IMEI number of device ( padded with zeros)
 */
public static String getIMEI(Activity activity) {
    try {
        TelephonyManager telephonyManager = (TelephonyManager) activity
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imei = telephonyManager.getDeviceId();
        if (imei == null)
            imei = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
        return imei;
    } catch (Exception e) {
    }
    return "EEEE-EEEE-EEEE-E";
}

From source file:Main.java

/**
 * @param context//  w  w w. j a  va  2s.c  om
 * @return String
 * @throws
 * @Title: getPhoneId
 * @Description: TODO
 */
public static String getPhoneId(Context context) {
    if (context == null) {
        return "";
    }
    if (checkPermission(context, "android.permission.READ_PHONE_STATE")) {
        String phoneId = "";
        if (checkPhoneState(context)) {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            phoneId = tm.getDeviceId();
            if (phoneId != null) {
                return phoneId;
            }
        }
    }
    return "";
}

From source file:Main.java

public static String getDeviceKey(Context ctx) {

    final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(ctx.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

public static String getPhoneStatus(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "honeType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
    return str;//from  www.ja  v a 2  s.c om
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return "000000000000000";
    }//from  w  w w  .ja  va 2s  . c o  m
    return tm.getDeviceId();
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return "null";
    } else {//from ww w .  j  a  v  a  2s  .  c  o  m
        String id = tm.getDeviceId();
        return id == null ? "null" : id;
    }
}

From source file:Main.java

public static String getDeviceId(Context context) {

    if (deviceId == null) {

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

        String tmDevice, tmSerial, tmPhone, 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());
        deviceId = deviceUuid.toString();

        System.err.println(deviceId);
    }/*from   w  w  w . jav  a  2 s  . c  om*/
    return deviceId;
}

From source file:Main.java

public static String getDeviceInfo(Context context) {
    try {// w  w  w . jav  a  2 s. c  o  m
        android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);

        String device_id = tm.getDeviceId();

        if (TextUtils.isEmpty(device_id)) {
            android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context
                    .getSystemService(Context.WIFI_SERVICE);
            device_id = wifi.getConnectionInfo().getMacAddress();
        }
        if (TextUtils.isEmpty(device_id)) {
            device_id = android.provider.Settings.Secure.getString(context.getContentResolver(),
                    android.provider.Settings.Secure.ANDROID_ID);
        }
        return device_id;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String getDeviceInfo(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    StringBuilder sb = new StringBuilder();
    sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
    sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
    sb.append("\nLine1Number = " + tm.getLine1Number());
    sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
    sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
    sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
    sb.append("\nNetworkType = " + tm.getNetworkType());
    sb.append("\nPhoneType = " + tm.getPhoneType());
    sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
    sb.append("\nSimOperator = " + tm.getSimOperator());
    sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
    sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
    sb.append("\nSimState = " + tm.getSimState());
    sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
    sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());

    return sb.toString();
}

From source file:Main.java

private static final boolean mayOnEmulatorViaTelephonyDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return false;
    }/*from  ww w  .  j  a v  a2s .  c o  m*/

    String deviceId = tm.getDeviceId();
    if (TextUtils.isEmpty(deviceId)) {
        return false;
    }

    /**
     * device id of telephony likes '0*'
     */
    for (int i = 0; i < deviceId.length(); i++) {
        if (deviceId.charAt(i) != '0') {
            return false;
        }
    }

    return true;
}