is Sim Exists - Android Phone

Android examples for Phone:Sim

Description

is Sim Exists

Demo Code


//package com.java2s;
import android.content.Context;
import android.telephony.TelephonyManager;

public class Main {
    public static boolean isSimExists(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        int SIM_STATE = telephonyManager.getSimState();

        if (SIM_STATE == TelephonyManager.SIM_STATE_READY)
            return true;
        else {//from w w w  . j av a2  s  .  c om
            switch (SIM_STATE) {
            case TelephonyManager.SIM_STATE_ABSENT: // SimState =
                // "No Sim Found!";
                break;
            case TelephonyManager.SIM_STATE_NETWORK_LOCKED: // SimState =
                // "Network Locked!";
                break;
            case TelephonyManager.SIM_STATE_PIN_REQUIRED: // SimState =
                // "PIN Required to access SIM!";
                break;
            case TelephonyManager.SIM_STATE_PUK_REQUIRED: // SimState =
                // "PUK Required to access SIM!";
                // // Personal
                // Unblocking Code
                break;
            case TelephonyManager.SIM_STATE_UNKNOWN: // SimState =
                // "Unknown SIM State!";
                break;
            }
            return false;
        }
    }
}

Related Tutorials