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

The following examples show how to use android.telephony.TelephonyManager#getDeviceId() . 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 File: ai.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
protected final String g()
{
    if (f == null && a != null)
    {
        b = (TelephonyManager)a.getSystemService("phone");
        if (b != null)
        {
            f = b.getDeviceId();
        }
    }
    if (f != null)
    {
        return f;
    } else
    {
        return "";
    }
}
 
Example 2
Source File: VenvyDeviceUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取手机IMEI号,需要<uses-permission
 * android:name="android.permission.READ_PHONE_STATE" />
 *
 * @param context
 * @return
 */
public static String getIMEI(final Context context) {
    String IMEI = "";
    if (context == null) {
        return IMEI;
    }
    TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    if (PermissionCheckHelper.isPermissionGranted(context, Manifest.permission.READ_PHONE_STATE)) {
        IMEI = telephonyManager.getDeviceId();
        if(TextUtils.isEmpty(IMEI)){
            // 部分Android 版本下获取的DeviceId为null的解决方案
            IMEI = Settings.Secure.getString(context.getApplicationContext().getContentResolver(),Settings.Secure.ANDROID_ID);
        }
    } else {
        IMEI = "000000000000000";
    }
    return IMEI;
}
 
Example 3
Source File: DeviceUtil.java    From talk-android with MIT License 5 votes vote down vote up
public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = "";
    try {
        deviceId = tm.getDeviceId();
    } catch (Exception e) {
        e.printStackTrace();
    }
    String macAddress = getMacAddress();
    return deviceId + "-" + macAddress;
}
 
Example 4
Source File: TelephoneUtil.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * MTK Phone.
 * <p>
 * 获取 MTK 神机的双卡 IMSI、IMSI 信息
 */
public static TeleInfo getMtkTeleInfo2(Context context) {
    try {
        TeleInfo teleInfo = new TeleInfo();
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Class<?> phone = Class.forName("com.android.internal.telephony.Phone");
        Field fields1 = phone.getField("GEMINI_SIM_1");
        fields1.setAccessible(true);
        int simId_1 = (Integer) fields1.get(null);
        Field fields2 = phone.getField("GEMINI_SIM_2");
        fields2.setAccessible(true);
        int simId_2 = (Integer) fields2.get(null);

        Method getDefault = TelephonyManager.class.getMethod("getDefault", int.class);
        TelephonyManager tm1 = (TelephonyManager) getDefault.invoke(tm, simId_1);
        TelephonyManager tm2 = (TelephonyManager) getDefault.invoke(tm, simId_2);

        String imsi_1 = tm1.getSubscriberId();
        String imsi_2 = tm2.getSubscriberId();
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        String imei_1 = tm1.getDeviceId();
        String imei_2 = tm2.getDeviceId();
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        int phoneType_1 = tm1.getPhoneType();
        int phoneType_2 = tm2.getPhoneType();
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;

        LogUtils.i("MTK2: " + teleInfo);
        return teleInfo;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 5
Source File: HelperMethods.java    From PhoneMonitor with GNU General Public License v3.0 5 votes vote down vote up
static String getIMEI(Context context) {
    String retval = "";
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        retval = telephonyManager.getDeviceId();
    }
    return retval;
}
 
Example 6
Source File: DatapointHelper.java    From Beats with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Gets the device's telephony ID (e.g. IMEI/MEID).
 * <p>
 * Note: this method will return null if {@link permission#READ_PHONE_STATE} is not available. This method will also return
 * null on devices that do not have telephony.
 *
 * @param context The context used to access the phone state.
 * @return An the {@link TelephonyManager#getDeviceId()}. Null if an ID is not available, or if
 *         {@link permission#READ_PHONE_STATE} is not available.
 */
public static String getTelephonyDeviceIdOrNull(final Context context)
{
    if (Constants.CURRENT_API_LEVEL >= 7)
    {

        final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", STRING_CLASS_ARRAY, HARDWARE_TELEPHONY); //$NON-NLS-1$
        if (!hasTelephony.booleanValue())
        {
            if (Constants.IS_LOGGABLE)
            {
                Log.i(Constants.LOG_TAG, "Device does not have telephony; cannot read telephony id"); //$NON-NLS-1$
            }

            return null;
        }
    }

    /*
     * Note: Sometimes Android will deny a package READ_PHONE_STATE permissions, even if the package has the permission. It
     * appears to be a race condition that occurs during installation.
     */
    String id = null;
    if (context.getPackageManager().checkPermission(permission.READ_PHONE_STATE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED)
    {
        final TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        id = manager.getDeviceId();
    }
    else
    {
        if (Constants.IS_LOGGABLE)
        {
            Log.w(Constants.LOG_TAG, "Application does not have permission READ_PHONE_STATE; determining device id is not possible.  Please consider requesting READ_PHONE_STATE in the AndroidManifest"); //$NON-NLS-1$
        }
    }

    return id;
}
 
Example 7
Source File: ImsiUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 展讯芯片的判断
 * @return
 */
public IMSInfo initSpreadDoubleSim() {
    IMSInfo imsInfo = null;
    try {
        Class<?> c = Class
                .forName("com.android.internal.telephony.PhoneFactory");
        Method m = c.getMethod("getServiceName", String.class, int.class);
        String spreadTmService = (String) m.invoke(c,
                Context.TELEPHONY_SERVICE, 1);
        TelephonyManager tm = (TelephonyManager) mContext
                .getSystemService(Context.TELEPHONY_SERVICE);
        imsi_1 = tm.getSubscriberId();
        imei_1 = tm.getDeviceId();
        TelephonyManager tm1 = (TelephonyManager) mContext
                .getSystemService(spreadTmService);
        imsi_2 = tm1.getSubscriberId();
        imei_2 = tm1.getDeviceId();
        imsInfo = new IMSInfo();
        imsInfo.chipName = "展讯芯片";
        imsInfo.imei_1 = imei_1;
        imsInfo.imei_2 = imei_2;
        imsInfo.imsi_1 = imsi_1;
        imsInfo.imsi_2 = imsi_2;
    } catch (Exception e) {
        imsInfo = null;
        return imsInfo;
    }
    return imsInfo;
}
 
Example 8
Source File: Device.java    From letv with Apache License 2.0 5 votes vote down vote up
private static String getSystemDeviceID(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService("phone");
    if (tm != null) {
        return tm.getDeviceId();
    }
    FLOG.e(TAG, "get telephony service failed while getting deviceId");
    return null;
}
 
Example 9
Source File: CommonUtils.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取 IMEI
 */
public static String getIMEI(Context context) {
    try {
        if (checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
            TelephonyManager telephonyMgr =
                    (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            if (telephonyMgr != null) {
                return telephonyMgr.getDeviceId();
            }
        }
    } catch (Throwable ignore) {
        ExceptionUtil.exceptionThrow(ignore);
    }
    return Constants.EMPTY;
}
 
Example 10
Source File: MainActivity.java    From mpush-android with Apache License 2.0 5 votes vote down vote up
private String getDeviceId() {
    TelephonyManager tm = (TelephonyManager) this.getSystemService(Activity.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();
    if (TextUtils.isEmpty(deviceId)) {
        String time = Long.toString((System.currentTimeMillis() / (1000 * 60 * 60)));
        deviceId = time + time;
    }
    return deviceId;
}
 
Example 11
Source File: e.java    From letv with Apache License 2.0 5 votes vote down vote up
public String f() {
    TelephonyManager telephonyManager = (TelephonyManager) this.b.getSystemService("phone");
    if (telephonyManager == null) {
    }
    try {
        if (bt.a(this.b, "android.permission.READ_PHONE_STATE")) {
            return telephonyManager.getDeviceId();
        }
        return null;
    } catch (Exception e) {
        return null;
    }
}
 
Example 12
Source File: SystemBasicInfo.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
public static String getDeviceId(Context context) {
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getDeviceId();
    } catch (Exception e) {
        return "null";
    }
}
 
Example 13
Source File: Utils.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("MissingPermission")
public static String getImei(Context context) {
    String imei = "";
    try {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        imei = telephonyManager.getDeviceId();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return imei;
}
 
Example 14
Source File: AppUtil.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * get the current version of current application
 */
public static String getImei( Context context) {
    if (TextUtils.isEmpty(imei)) {
        if(context.checkCallingOrSelfPermission( Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_GRANTED){
            TelephonyManager tm = (TelephonyManager) context.getApplicationContext()
                    .getSystemService(Context.TELEPHONY_SERVICE);
            imei = tm.getDeviceId();
        }
    }
    return imei;
}
 
Example 15
Source File: GetDeviceIdTask.java    From android-performance with MIT License 5 votes vote down vote up
@Override
public void run() {
    // 真正自己的代码
    TelephonyManager tManager = (TelephonyManager) mContext.getSystemService(
            Context.TELEPHONY_SERVICE);
    mDeviceId = tManager.getDeviceId();
    PerformanceApp app = (PerformanceApp) mContext;
    app.setDeviceId(mDeviceId);
}
 
Example 16
Source File: ExampleUtil.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
public static String getImei(Context context, String imei) {
	try {
		TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		imei = telephonyManager.getDeviceId();
	} catch (Exception e) {
		Log.e(ExampleUtil.class.getSimpleName(), e.getMessage());
	}
	return imei;
}
 
Example 17
Source File: TelephoneUtil.java    From android-common with Apache License 2.0 5 votes vote down vote up
/**
 * MTK Phone.
 *
 * 获取 MTK 神机的双卡 IMSI、IMSI 信息
 */
public static TeleInfo getMtkTeleInfo2(Context context) {
    TeleInfo teleInfo = new TeleInfo();
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        Class<?> phone = Class.forName("com.android.internal.telephony.Phone");
        Field fields1 = phone.getField("GEMINI_SIM_1");
        fields1.setAccessible(true);
        int simId_1 = (Integer) fields1.get(null);
        Field fields2 = phone.getField("GEMINI_SIM_2");
        fields2.setAccessible(true);
        int simId_2 = (Integer) fields2.get(null);

        Method getDefault = TelephonyManager.class.getMethod("getDefault", int.class);
        TelephonyManager tm1 = (TelephonyManager) getDefault.invoke(tm, simId_1);
        TelephonyManager tm2 = (TelephonyManager) getDefault.invoke(tm, simId_2);

        String imsi_1 = tm1.getSubscriberId();
        String imsi_2 = tm2.getSubscriberId();
        teleInfo.imsi_1 = imsi_1;
        teleInfo.imsi_2 = imsi_2;

        String imei_1 = tm1.getDeviceId();
        String imei_2 = tm2.getDeviceId();
        teleInfo.imei_1 = imei_1;
        teleInfo.imei_2 = imei_2;

        int phoneType_1 = tm1.getPhoneType();
        int phoneType_2 = tm2.getPhoneType();
        teleInfo.phoneType_1 = phoneType_1;
        teleInfo.phoneType_2 = phoneType_2;
    } catch (Exception e) {
        e.printStackTrace();
    }
    Log.i(TAG, "MTK2: " + teleInfo);
    return teleInfo;
}
 
Example 18
Source File: PhoneUtils.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
/**
 * 获取手机状态信息
 * <p>需添加权限<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 * <p>返回如下
 * <pre>
 * DeviceId(IMEI) = 99000311726612
 * DeviceSoftwareVersion = 00
 * Line1Number =
 * NetworkCountryIso = cn
 * NetworkOperator = 46003
 * NetworkOperatorName = 中国电信
 * NetworkType = 6
 * honeType = 2
 * SimCountryIso = cn
 * SimOperator = 46003
 * SimOperatorName = 中国电信
 * SimSerialNumber = 89860315045710604022
 * SimState = 5
 * SubscriberId(IMSI) = 460030419724900
 * VoiceMailNumber = *86
 * <pre/>
 */
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;
}
 
Example 19
Source File: SystemUtils.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
public static String getDeviceId()
{
    TelephonyManager tm = (TelephonyManager) AppMain.getInstance().getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getDeviceId();
}
 
Example 20
Source File: PhoneUtils.java    From Android-UtilCode with Apache License 2.0 2 votes vote down vote up
/**
 * 获取IMEI码
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
 *
 * @return IMEI码
 */
@SuppressLint("HardwareIds")
public static String getIMEI() {
    TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null ? tm.getDeviceId() : null;
}