Check if a sim card Network service is available or not

ⅰ亾dé卋堺 提交于 2019-12-06 11:54:09

问题


Hi I am developing an application that changes a button according to the SIM STATE

I am using 1 for NO SIM and 5 for SIM READY

In few case I have no service for example, if the SIM card is an international card , It doesn't work in other places. What is the SIM State for this type of condition.

Please suggest how to check when there is a SIM card but no service. Thanks!


回答1:


Hi Please can you try this code...

ref link : 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;
        }


来源:https://stackoverflow.com/questions/21694440/check-if-a-sim-card-network-service-is-available-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!