如何检查SIM卡是否可在Android设备? [英] How can I check whether the Sim Card is available in an android device?

查看:169
本文介绍了如何检查SIM卡是否可在Android设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我需要帮助检查设备是否具有SIM卡编程。请提供样品code。

Friends, I need help checking whether a device has a sim card programatically. Please provide sample code.

感谢。

推荐答案

使用TelephonyManager。

Use TelephonyManager.

<一个href="http://developer.android.com/reference/android/telephony/TelephonyManager.html">http://developer.android.com/reference/android/telephony/TelephonyManager.html

由于Falmarri音符,你的将会的要使用的 getPhoneType 的首先,来看看你甚至处理一个GSM电话。如果你是,那么你也可以拿到SIM卡状态。

As Falmarri notes, you will want to use getPhoneType FIRST of all, to see if you are even dealing with a GSM phone. If you are, then you can also get the SIM state.

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

这篇关于如何检查SIM卡是否可在Android设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆