检查SIM卡网络服务是否可用

时间:2014-02-11 06:11:46

标签: android telephonymanager phone-state-listener

您好我正在开发一个根据SIM状态更改按钮的应用程序

我使用1表示无SIM卡,5表示SIM READY

在少数情况下我没有服务,例如,如果SIM卡是国际卡,它在其他地方不起作用。这种情况的SIM状态是什么。

请建议如何检查何时有SIM卡但没有服务。谢谢!

1 个答案:

答案 0 :(得分:5)

嗨请你试试这段代码......

参考链接:https://stackoverflow.com/a/3982768/900338

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