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:de.ub0r.android.lib.DonationHelper.java

/**
 * Get MD5 hash of the IMEI (device id).
 * //from  w  w  w. j  a v  a  2s.c o m
 * @param context
 *            {@link Context}
 * @return MD5 hash of IMEI
 */
public static String getImeiHash(final Context context) {
    if (imeiHash == null) {
        // get imei
        TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        final String did = mTelephonyMgr.getDeviceId();
        if (did != null) {
            imeiHash = Utils.md5(did);
        } else {
            imeiHash = Utils.md5(Build.BOARD + Build.BRAND + Build.PRODUCT + Build.DEVICE);
        }
    }
    return imeiHash;
}

From source file:Utils.GenericUtils.java

public static Boolean validateApplicationLicense(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String devId = tm.getDeviceId();
    //showPlainAlert(context, "Device Id", devId);
    return true;/*  www.  ja v a 2  s  .  c  o  m*/
}

From source file:com.vinexs.tool.Utility.java

/**
 * <p>Get user deivce id.</p>
 * Required Permission &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
 *
 * @param context Application context// w  w  w .  j  av  a2 s.c o m
 * @return Deivce id in string.
 */
public static String getUserDeviceId(Context context) {
    try {
        if (!hasPermission(context, "android.permission.READ_PHONE_STATE")) {
            throw new Exception();
        }
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getDeviceId();
    } catch (Exception e) {
        return Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    }
}

From source file:com.segment.analytics.internal.Utils.java

/** Creates a unique device id. */
public static String getDeviceId(Context context) {
    String androidId = getString(context.getContentResolver(), ANDROID_ID);
    if (!isNullOrEmpty(androidId) && !"9774d56d682e549c".equals(androidId) && !"unknown".equals(androidId)
            && !"000000000000000".equals(androidId)) {
        return androidId;
    }/*  w  w w .j a  v a 2 s . c  om*/

    // Serial number, guaranteed to be on all non phones in 2.3+
    if (!isNullOrEmpty(Build.SERIAL)) {
        return Build.SERIAL;
    }

    // Telephony ID, guaranteed to be on all phones, requires READ_PHONE_STATE permission
    if (hasPermission(context, READ_PHONE_STATE) && hasFeature(context, FEATURE_TELEPHONY)) {
        TelephonyManager telephonyManager = getSystemService(context, TELEPHONY_SERVICE);
        String telephonyId = telephonyManager.getDeviceId();
        if (!isNullOrEmpty(telephonyId)) {
            return telephonyId;
        }
    }

    // If this still fails, generate random identifier that does not persist across installations
    return UUID.randomUUID().toString();
}

From source file:com.wbtech.common.CommonUtil.java

/**
 * ?deviceid//from  w w w  .  j  av  a2s.  co  m
 * @param context
 *             <uses-permission android:name="READ_PHONE_STATE" /> 
 * @return
 */
public static String getDeviceID(Context context) {
    if (checkPermissions(context, "android.permission.READ_PHONE_STATE")) {
        String deviceId = "";
        if (checkPhoneState(context)) {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            deviceId = tm.getDeviceId();
        }
        if (deviceId != null) {
            if (UmsConstants.DebugMode) {
                Log.d("commonUtil", "deviceId:" + deviceId);
            }

            return deviceId;
        } else {
            if (UmsConstants.DebugMode) {
                Log.e("commonUtil", "deviceId is null");
            }

            return null;
        }
    } else {
        if (UmsConstants.DebugMode) {
            Log.e("lost permissioin", "lost----->android.permission.READ_PHONE_STATE");
        }

        return "";
    }
}

From source file:com.silentcircle.silenttext.util.DeviceUtils.java

public static String getDeviceID(Context context) {
    TelephonyManager telephony = context != null
            ? (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)
            : null;/*www  .  jav  a 2  s.  c o m*/
    return telephony != null ? telephony.getDeviceId() : UUID.randomUUID().toString();
}

From source file:ru.dublgis.androidhelpers.DesktopUtils.java

public static String getTelephonyDeviceId(final Context ctx) {
    try {/*from  w  w w .j a va 2 s .  c o  m*/
        TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm == null) {
            return "";
        }
        return tm.getDeviceId();
    } catch (final Throwable e) {
        Log.e(TAG, "getTelephonyDeviceId exception: ", e);
        return "";
    }
}

From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java

public static String getHWID(Context cx) {
    if (sHWID != null)
        return sHWID;

    // If we're on SDK version > 8, use Build.SERIAL
    if (android.os.Build.VERSION.SDK_INT > 8) {
        sHWID = android.os.Build.SERIAL;
    }/*from  w w w.  j  a v a  2 s.  c o  m*/

    if (sHWID != null)
        return sHWID;

    // Otherwise, try from the telephony manager
    TelephonyManager mTelephonyMgr = (TelephonyManager) cx.getSystemService(TELEPHONY_SERVICE);
    if (mTelephonyMgr != null) {
        sHWID = mTelephonyMgr.getDeviceId();
    }

    if (sHWID != null)
        return sHWID;

    // Otherwise, try WIFI_SERVICE and use the wifi manager
    WifiManager wifiMan = (WifiManager) cx.getSystemService(Context.WIFI_SERVICE);
    if (wifiMan != null) {
        WifiInfo wifi = wifiMan.getConnectionInfo();
        if (wifi != null) {
            sHWID = "wifimac" + wifi.getMacAddress();
        }
    }

    if (sHWID != null)
        return sHWID;

    sHWID = "0011223344556677";

    return sHWID;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static String getDeviceId() {
    TelephonyManager mgr = (TelephonyManager) BaseApplication.getAppContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = null;/*from ww w  .  j  a  va2s . c o m*/
    try {
        deviceId = mgr.getDeviceId();
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (TextUtils.isEmpty(deviceId)) {
        deviceId = "";
    }

    return MiscUtils.generateMD5String(deviceId);
}

From source file:com.prey.json.actions.Imei.java

public HttpDataService run(Context ctx, List<ActionResult> lista, JSONObject parameters) {
    TelephonyManager mTelephonyMgr = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    String imeiValue = mTelephonyMgr.getDeviceId();
    HttpDataService data = new HttpDataService("imei");
    data.setSingleData(imeiValue);//w  w  w .  jav a 2s .  c  o  m
    return data;
}