TelephonyManager.java

参考Android 8.0 源码

  我们使用下面的代码来获取TelephonyManager。

TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

获取SIM卡状态

  我们获取到TelephonyManager之后,就可以使用getSimState()方法来获取到SIM卡的状态了。

int sim_state = telephonyManager.getSimState();

  获取的sim_state有几种常量值,如下所示:

//未知状态,表示SIM卡正在状态之间转换;
public static final int SIM_STATE_UNKNOWN = 0;

//设备中没有可用的SIM卡;
public static final int SIM_STATE_ABSENT = 1;

//已锁定,需要用户的SIM卡PIN才能解锁;
public static final int SIM_STATE_PIN_REQUIRED = 2;

//已锁定,需要用户的SIM卡PUK才能解锁;
public static final int SIM_STATE_PUK_REQUIRED = 3;

//已锁定,需要网络PIN才能解锁;
public static final int SIM_STATE_NETWORK_LOCKED = 4;

//SIM卡就绪;
public static final int SIM_STATE_READY = 5;

//SIM卡未就绪;
public static final int SIM_STATE_NOT_READY = 6;

//SIM卡错误,永久禁用;
public static final int SIM_STATE_PERM_DISABLED = 7;

//SIM错误,卡存在但有故障;
public static final int SIM_STATE_CARD_IO_ERROR = 8;

//SIM卡受限,卡存在但由于运营商限制而无法使用;
public static final int SIM_STATE_CARD_RESTRICTED = 9;

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--------------------last line for now-------------------