is Sim Card Exists - Android Hardware

Android examples for Hardware:Sim Card

Description

is Sim Card 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 {/* w  w w. j  a  va 2 s.  com*/
            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