Java Code Examples for android.telephony.TelephonyManager#SIM_STATE_UNKNOWN

The following examples show how to use android.telephony.TelephonyManager#SIM_STATE_UNKNOWN . 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: Net.java    From HttpInfo with Apache License 2.0 6 votes vote down vote up
public static boolean hasSimCard(Context context) {
    boolean result = true;
    try {
        TelephonyManager telMgr = (TelephonyManager)
                context.getSystemService(Context.TELEPHONY_SERVICE);
        int simState = telMgr.getSimState();
        switch (simState) {
            case TelephonyManager.SIM_STATE_ABSENT:
                result = false;
                break;
            case TelephonyManager.SIM_STATE_UNKNOWN:
                result = false;
                break;
            default:
                break;
        }
    } catch (Exception e) {
        //ignore
    }
    return result;
}
 
Example 2
Source File: PhoneUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 获取 SIM 卡状态
 * @param slotIndex 卡槽索引
 * @return SIM 卡状态
 */
public static int getSimState(final int slotIndex) {
    try {
        TelephonyManager telephonyManager = AppUtils.getTelephonyManager();
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
            return telephonyManager.getSimState();
        } else { // 使用默认卡槽
            if (slotIndex == -1) {
                return telephonyManager.getSimState();
            }
            // 26 以上有公开 api
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                return telephonyManager.getSimState(slotIndex);
            }
            // 反射调用方法
            Method method = telephonyManager.getClass().getDeclaredMethod("getSimState");
            method.setAccessible(true);
            return (Integer) (method.invoke(telephonyManager, slotIndex));
        }
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getSimState");
    }
    return TelephonyManager.SIM_STATE_UNKNOWN;
}
 
Example 3
Source File: SimCardInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是否包含SIM卡
 *
 * @param context 上下文
 * @return 状态 是否包含SIM卡
 */
private static boolean hasSimCard(Context context) {
    boolean result = true;
    try {
        TelephonyManager telMgr = (TelephonyManager)
                context.getSystemService(Context.TELEPHONY_SERVICE);
        int simState = telMgr.getSimState();
        switch (simState) {
            case TelephonyManager.SIM_STATE_ABSENT:
                result = false;
                break;
            case TelephonyManager.SIM_STATE_UNKNOWN:
                result = false;
                break;
            default:
                break;
        }
    } catch (Exception e) {

    }
    return result;
}
 
Example 4
Source File: TypeTranslators.java    From under-the-hood with Apache License 2.0 6 votes vote down vote up
/**
 * @param simState expected to be from {@link TelephonyManager#getSimState()}
 * @return human-readable state
 */
public static String translateSimState(int simState) {
    switch (simState) {
        case TelephonyManager.SIM_STATE_READY:
            return "STATE_READY";
        case TelephonyManager.SIM_STATE_PUK_REQUIRED:
        case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
        case TelephonyManager.SIM_STATE_PIN_REQUIRED:
            return "STATE_LOCKED (" + simState + ")";
        case TelephonyManager.SIM_STATE_ABSENT:
            return "STATE_ABSENT";
        default:
        case TelephonyManager.SIM_STATE_UNKNOWN:
            return "UNKNOWN (" + simState + ")";
    }
}
 
Example 5
Source File: DeviceUtil.java    From DoingDaily with Apache License 2.0 6 votes vote down vote up
/**
 * @param context
 * @return
 */
public static String getIMSI(Context context) {
    String imsi = "00000000000000";
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String model = Build.MANUFACTURER + Build.MODEL;

    if (tm == null || (model.toLowerCase().contains("htc") && (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT || tm.getSimState() == TelephonyManager.SIM_STATE_UNKNOWN))) {
        return imsi;
    }
    String imsiTmp = tm.getSubscriberId();
    if (!TextUtils.isEmpty(imsiTmp)) {
        imsi = imsiTmp;
    }

    return imsi;
}
 
Example 6
Source File: TelInfo.java    From DualSIMCard with Apache License 2.0 6 votes vote down vote up
private static boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws ITgerMethodNotFoundException {
    boolean isReady = false;
    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    try {
        Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
        Class<?>[] parameter = new Class[1];
        parameter[0] = int.class;
        Method getSimState = telephonyClass.getMethod(predictedMethodName, parameter);
        Object[] obParameter = new Object[1];
        obParameter[0] = slotID;
        Object ob_phone = getSimState.invoke(telephony, obParameter);

        if (ob_phone != null) {
            int simState = Integer.parseInt(ob_phone.toString());
            telInf.sim2_STATE = simState(simState);
            if ((simState != TelephonyManager.SIM_STATE_ABSENT) && (simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
                isReady = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new ITgerMethodNotFoundException(predictedMethodName);
    }

    return isReady;
}
 
Example 7
Source File: NetworkConnUtil.java    From RairDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 检查sim卡状态
 *
 * @return
 */
public static boolean checkSimState(Context context) {
    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    if (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT
            || tm.getSimState() == TelephonyManager.SIM_STATE_UNKNOWN) {
        return false;
    }

    return true;
}