3

TelephonyManager.getSimState()我想知道“飞行模式”打开时返回的 SIM 状态的值是多少?这似乎没有在 SDK 规范的任何地方直接指定。

实际上我需要使用方法获取 SIM 运营商代码(即 MCC+MNC)getSimOperator(),但 JavaDoc 声明要使用该方法:

SIM 状态必须为SIM_STATE_READY

更新

我在模拟器下对其进行了测试,并在SIM_STATE_UNKNOWN打开飞行模式后返回(javadoc 将其描述为“状态之间的转换”)。但是我想知道这是否是Android手机上的常见行为?

4

2 回答 2

3

在搜索 Android 4.1 源代码后,我在其中一个私有类中找到了以下代码com.android.internal.telephony.IccCard

public State getState() {
  if (mState == null) {
      switch(mPhone.mCM.getRadioState()) {
          /* This switch block must not return anything in
           * State.isLocked() or State.ABSENT.
           * If it does, handleSimStatus() may break
           */
          case RADIO_OFF:
          case RADIO_UNAVAILABLE:
          case SIM_NOT_READY:
          case RUIM_NOT_READY:
              return State.UNKNOWN;
          case SIM_LOCKED_OR_ABSENT:
          case RUIM_LOCKED_OR_ABSENT:
              //this should be transient-only
              return State.UNKNOWN;
          case SIM_READY:
          case RUIM_READY:
          case NV_READY:
              return State.READY;
          case NV_NOT_READY:
              return State.ABSENT;
      }
  } else {
      return mState;
  }

  Log.e(mLogTag, "IccCard.getState(): case should never be reached");
  return State.UNKNOWN;
}  

因此State.UNKNOWN,只要无线电状态是RADIO_OFFRADIO_UNAVAILABLE之一,就会返回。然后State.UNKNOWNSIM_STATE_UNKNOWN通过方法转换为常量TelephonyManager.getSimState()

结论是:打开飞行模式时getSimState会返回SIM_STATE_UNKNOWN

于 2011-10-21T15:00:02.943 回答
2

是的,这是安卓手机上的常见行为。查看 TelephonyManager 类中 getSimState() 方法的实现:

public int getSimState() {
    String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE);
    if ("ABSENT".equals(prop)) {
        return SIM_STATE_ABSENT;
    }
    else if ("PIN_REQUIRED".equals(prop)) {
        return SIM_STATE_PIN_REQUIRED;
    }
    else if ("PUK_REQUIRED".equals(prop)) {
        return SIM_STATE_PUK_REQUIRED;
    }
    else if ("NETWORK_LOCKED".equals(prop)) {
        return SIM_STATE_NETWORK_LOCKED;
    }
    else if ("READY".equals(prop)) {
        return SIM_STATE_READY;
    }
    else {
        return SIM_STATE_UNKNOWN;
    }
}
于 2011-10-21T13:12:50.797 回答