android 判断是否有sim卡

时间:2021-04-12 14:49:19
/**
* 判断是否包含SIM卡
*
* @return 状态
*/
public static boolean ishasSimCard(Context context) {
TelephonyManager telMgr = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
int simState = telMgr.getSimState();
boolean result = true;
switch (simState) {
case TelephonyManager.SIM_STATE_ABSENT:
result = false; // 没有SIM卡
break;
case TelephonyManager.SIM_STATE_UNKNOWN:
result = false;
break;
}
Log.d(TAG, result ? "有SIM卡" : "无SIM卡");
return result;
}