Android检测是否有SIM卡

/**
 * 打电话
 */
public static void callPhone(Context context, String phone){
    if(hasSimCard(context)){
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
        MyApplication.context.startActivityForResult(intent, 1);
    }else{
        Toast...
    }

}
/**
 * 判断是否包含SIM卡
 *
 * @return 状态
 */
public static boolean hasSimCard(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("try", result ? "有SIM卡" : "无SIM卡");
    return result;
}

参考文章
https://blog.csdn.net/weixin_40391500/article/details/78232606

你可能感兴趣的:(Android检测是否有SIM卡)