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

public static String getPhoneDeviceId(Context context) {
    TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telManager == null ? null : telManager.getDeviceId();
}

From source file:Main.java

public static String getIMEI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String IMEI = telephonyManager.getDeviceId();
    return IMEI;/* w  ww  .  j  a  v  a2 s.  c om*/
}

From source file:Main.java

public static String getDevice_id(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        return tm.getDeviceId();
    }//www  .ja  v  a 2  s  . com
    return "";

}

From source file:Main.java

public static String getDeviceId(Context context) {
    String deviceId = "";
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        deviceId = tm.getDeviceId();
    }/*  ww w. ja  va 2 s .co  m*/
    return deviceId;
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String uuid = tm.getDeviceId();
    if (uuid == null) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        String mac = wifiManager.getConnectionInfo().getMacAddress();
        if (mac == null)
            throw new IllegalStateException();
        return mac;
    }// w ww. ja v  a 2s. c  o m
    return uuid;
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();
    String macAddress = getMacAddress();
    return deviceId + "-" + macAddress;
}

From source file:Main.java

public static String getIMEI(Context context, String imei) {
    try {//ww w.  ja  va2  s  .com
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        imei = telephonyManager.getDeviceId();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return imei;
}

From source file:Main.java

/**
 * get app imei/*w  ww.j  a  v  a2 s. c  o m*/
 * @param context
 * @return
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getDeviceIMEI(Context context) {
    String deviceId;
    if (isPhone(context)) {
        TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        deviceId = telephony.getDeviceId();
    } else {
        deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

    }
    return deviceId;
}

From source file:Main.java

public static String getDeviceID(Activity a) {
    TelephonyManager tm = (TelephonyManager) a.getApplicationContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    String id = tm.getDeviceId();
    if (id == null)
        id = "DefaultTwitchUser";
    return Integer.toHexString(id.hashCode());
}

From source file:Main.java

private static String generateDeviceUniqueIdentifier(Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice = "" + tm.getDeviceId();
    final String tmSerial = "" + tm.getSimSerialNumber();
    final String androidId = ""
            + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    final String packageBasedAndroidId = context.getPackageName() + androidId;

    UUID deviceUuid = new UUID(packageBasedAndroidId.hashCode(),
            ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();
}