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

/**
 * Gets an unique device Id depending on the sdk version
 *
 * @param context/*from w w w .j  a  v a2s.com*/
 * @return
 */
public static String getUniqueDeviceId(Context context) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
        return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    } else {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getDeviceId();
    }
}

From source file:Main.java

public static String getIMEI(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Activity.TELEPHONY_SERVICE);
    String imei = tm.getDeviceId();
    if (imei == null) {
        imei = "000000000000000";
    }//w  w  w . j  a  va2 s  .  c om
    return imei;
}

From source file:Main.java

/**
 * This Function return the Android DeviceID in String format. Always to add
 * following Permission in Manifest./*from   w  w  w. jav a  2  s .c  o m*/
 * 
 * Requires Permission: READ_PHONE_STATE
 * 
 * See below for @params.
 */

public static String getDeviceID(Context ctx) {

    TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    String iemi = telephonyManager.getDeviceId();
    return iemi;
}

From source file:Main.java

public static String getDeviceId(Context context) {
    String deviceId = "";
    if (context != null) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (!TextUtils.isEmpty(tm.getDeviceId())) {
            deviceId = tm.getDeviceId();
        }//from w w  w.j a  v a  2s . c  o m
    }
    return deviceId;
}

From source file:Main.java

/**
 * get device id//www  . j a v a 2s  .  c  om
 * @param context
 * @return
 */
public static String getDeviceId(Context context) {
    TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = telManager.getDeviceId();
    if (deviceId == null) {
        deviceId = new String("123456789012345");
    }

    return deviceId;
}

From source file:Main.java

public static String getIMEI(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager.getDeviceId() == null) {
        return null;
    } else {/*  ww w.j  a  v  a2s . c o m*/
        return telephonyManager.getDeviceId();
    }
}

From source file:Main.java

public static String getDeviceId(Activity activity) {
    TelephonyManager tm = (TelephonyManager) activity
            .getSystemService(android.content.Context.TELEPHONY_SERVICE);
    return tm.getDeviceId();
}

From source file:Main.java

public static String getDeviceId(Context context) {

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    Log.d("AppUtils", "getDeviceId:" + tm.getDeviceId());

    return tm.getDeviceId();
}

From source file:Main.java

/**
 * get Imei/*w  w w .  jav a  2  s  . co m*/
 * @param context 
 * @return imei
 * */
public static String getIMEI(Context context) {
    try {
        TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String imei = mTelephonyMgr.getDeviceId();
        return imei;
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

public static String getDeviceId(Context context) {

    if (context != null) {
        try {/*from   w ww. j  a  v a 2  s  .co m*/
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String device_id = tm.getDeviceId();
            return device_id;
        } catch (Exception e) {
        }
    }
    return null;
}