Check if a sim card Network service is available o

2020-07-24 05:11发布

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条回答
萌系小妹纸
2楼-- · 2020-07-24 05:55

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;
        }
查看更多
登录 后发表回答