Java Code Examples for android.telephony.TelephonyManager#getMeid()

The following examples show how to use android.telephony.TelephonyManager#getMeid() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Android-utils   File: DeviceUtils.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getDeviceId() {
    TelephonyManager tm =
            (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        //noinspection ConstantConditions
        String imei = tm.getImei();
        if (!TextUtils.isEmpty(imei)) return imei;
        String meid = tm.getMeid();
        return TextUtils.isEmpty(meid) ? "" : meid;

    }
    //noinspection ConstantConditions
    return tm.getDeviceId();
}
 
Example 2
Source Project: AndroidUtilCode   File: PhoneUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the unique device id.
 * <p>If the version of SDK is greater than 28, it will return an empty string.</p>
 * <p>Must hold {@code <uses-permission android:name="android.permission.READ_PHONE_STATE" />}</p>
 *
 * @return the unique device id
 */
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getDeviceId() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        return "";
    }
    TelephonyManager tm = getTelephonyManager();
    String deviceId = tm.getDeviceId();
    if (!TextUtils.isEmpty(deviceId)) return deviceId;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String imei = tm.getImei();
        if (!TextUtils.isEmpty(imei)) return imei;
        String meid = tm.getMeid();
        return TextUtils.isEmpty(meid) ? "" : meid;
    }
    return "";
}
 
Example 3
Source Project: sa-sdk-android   File: SensorsDataUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取设备唯一标识
 *
 * @param context Context
 * @param number 卡槽
 * @return 设备唯一标识
 */
private static String getDeviceID(Context context, int number) {
    String deviceId = "";
    try {
        if (!SensorsDataUtils.checkHasPermission(context, "android.permission.READ_PHONE_STATE")) {
            return deviceId;
        }

        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            if (number == -1) {
                deviceId = tm.getDeviceId();
            } else if (number == -2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                deviceId = tm.getMeid();
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                deviceId = tm.getDeviceId(number);
            }
        }
    } catch (Exception e) {
        SALog.printStackTrace(e);
    }
    return deviceId;
}
 
Example 4
Source Project: Box   File: DeviceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint({"HardwareIds", "MissingPermission"})
@RequiresPermission(READ_PHONE_STATE)
public static String getMEID(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) return "";
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? telephonyManager.getMeid() : telephonyManager.getDeviceId();
}
 
Example 5
Source Project: Android-utils   File: DeviceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getMEID() {
    TelephonyManager tm =
            (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        //noinspection ConstantConditions
        return tm.getMeid();
    }
    //noinspection ConstantConditions
    return tm.getDeviceId();
}
 
Example 6
Source Project: Box   File: DeviceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint({"HardwareIds", "MissingPermission"})
@RequiresPermission(READ_PHONE_STATE)
public static String getMEID(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) return "";
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? telephonyManager.getMeid() : telephonyManager.getDeviceId();
}