android.telephony.TelephonyManager.getSimState()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中android.telephony.TelephonyManager.getSimState()方法的一些代码示例,展示了TelephonyManager.getSimState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TelephonyManager.getSimState()方法的具体详情如下:
包路径:android.telephony.TelephonyManager
类名称:TelephonyManager
方法名:getSimState

TelephonyManager.getSimState介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private boolean isTelephonyEnabled(){
  TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
  return telephonyManager != null && telephonyManager.getSimState()==TelephonyManager.SIM_STATE_READY;
}

代码示例来源:origin: stackoverflow.com

TelephonyManager telMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
 int simState = telMgr.getSimState();
     switch (simState) {
       case TelephonyManager.SIM_STATE_ABSENT:
         // do something
         break;
       case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
         // do something
         break;
       case TelephonyManager.SIM_STATE_PIN_REQUIRED:
         // do something
         break;
       case TelephonyManager.SIM_STATE_PUK_REQUIRED:
         // do something
         break;
       case TelephonyManager.SIM_STATE_READY:
         // do something
         break;
       case TelephonyManager.SIM_STATE_UNKNOWN:
         // do something
         break;
     }

代码示例来源:origin: square/assertj-android

public TelephonyManagerAssert hasSimState(@TelephonyManagerSimState int state) {
 isNotNull();
 int actualState = actual.getSimState();
 //noinspection ResourceType
 assertThat(actualState) //
   .overridingErrorMessage("Expected SIM state <%s> but was <%s>.", simStateToString(state),
     simStateToString(actualState)) //
   .isEqualTo(state);
 return this;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldGetSimState() {
 assertThat(telephonyManager.getSimState()).isEqualTo(TelephonyManager.SIM_STATE_READY);
}

代码示例来源:origin: stackoverflow.com

telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
telephonyInfo.isSIM2Ready = false;

代码示例来源:origin: robolectric/robolectric

@Test
@Config(minSdk = O)
public void shouldGetSimStateUsingSlotNumber() {
 int expectedSimState = TelephonyManager.SIM_STATE_ABSENT;
 int slotNumber = 3;
 shadowOf(telephonyManager).setSimState(slotNumber, expectedSimState);
 assertThat(telephonyManager.getSimState(slotNumber)).isEqualTo(expectedSimState);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void resetSimStates_shouldRetainDefaultState() {
 shadowOf(telephonyManager).resetSimStates();
 assertThat(telephonyManager.getSimState()).isEqualTo(TelephonyManager.SIM_STATE_READY);
}

代码示例来源:origin: stackoverflow.com

TelephonyManager m = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
if (m.getSimState() != TelephonyManager.SIM_STATE_ABSENT){
 // SIM card
} else {
 // No SIM card
}

代码示例来源:origin: stackoverflow.com

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
   if(telephonyManager.getSimState()!= TelephonyManager.SIM_STATE_ABSENT)
   {
     //your code here
   }

代码示例来源:origin: stackoverflow.com

TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);  //gets the current TelephonyManager
if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT){
 //the device has a sim card
} else {
 //no sim card available
}

代码示例来源:origin: stackoverflow.com

TelephonyManager manager = (TelephonyManager) Context.getSystemService(Context.TELEPHONY_SERVICE);
int state = manager.getSimState();
if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
     //PIN/PUK is required
}

代码示例来源:origin: stackoverflow.com

public static boolean isSimSupport(Context context)
 {
   TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);  //gets the current TelephonyManager
   return !(tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT);
 }

代码示例来源:origin: yaozs/YzsLib

/**
 * 判断sim卡是否准备好
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isSimCardReady(Context context) {
  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY;
}

代码示例来源:origin: z-android/ZLayer

public static boolean isSimExist(Context context) {
  final TelephonyManager mTelephonyManager = (TelephonyManager) context
      .getSystemService(Context.TELEPHONY_SERVICE);
  int simState = mTelephonyManager.getSimState();
  if (simState == TelephonyManager.SIM_STATE_ABSENT
      || simState == TelephonyManager.SIM_STATE_UNKNOWN) {
    return false;
  }
  return true;
}

代码示例来源:origin: 0xm1nam0/RxCore

/**
 * 判断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;
}

代码示例来源:origin: StannyBing/ZXUtils

/**
   * 判断sim卡是否准备好
   *
   * @return {@code true}: 是<br>{@code false}: 否
   */
  public static boolean isSimCardReady() {
    TelephonyManager tm = (TelephonyManager) ZXApp.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    return tm != null && tm.getSimState() == TelephonyManager.SIM_STATE_READY;
  }
}

代码示例来源:origin: hoangkien0705/Android-UtilCode

/**
 * 判断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;
}

代码示例来源:origin: mukeshsolanki/country-picker-android

public Country getCountryFromSIM() {
 TelephonyManager telephonyManager =
   (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
 if (telephonyManager != null
   && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {
  return getCountryByISO(telephonyManager.getSimCountryIso());
 }
 return null;
}

代码示例来源:origin: malmstein/yahnac

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;
}

代码示例来源:origin: com.squareup.assertj/assertj-android

public TelephonyManagerAssert hasSimState(@TelephonyManagerSimState int state) {
 isNotNull();
 int actualState = actual.getSimState();
 //noinspection ResourceType
 assertThat(actualState) //
   .overridingErrorMessage("Expected SIM state <%s> but was <%s>.", simStateToString(state),
     simStateToString(actualState)) //
   .isEqualTo(state);
 return this;
}

相关文章