is Sim Ready - Android Phone

Android examples for Phone:Sim

Description

is Sim Ready

Demo Code


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

import android.telephony.TelephonyManager;
import java.lang.reflect.Method;

public class Main {

    public static boolean isSimReady(Context context, int slotID) {
        boolean isReady = false;
        if (context == null) {
            return false;
        }//from ww w .jav  a  2s  .  co  m

        if (slotID < 0 || slotID > 1) {
            return false;
        }
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);

            Class<?> mLoadClass = Class
                    .forName("android.telephony.TelephonyManager");

            Class<?>[] parameter = new Class[1];
            parameter[0] = int.class;
            Method getSimStateGemini = mLoadClass.getMethod(
                    "getSimStateGemini", parameter);

            Object[] obParameter = new Object[1];
            obParameter[0] = slotID;
            Object ob_phone = getSimStateGemini.invoke(telephonyManager,
                    obParameter);

            if (ob_phone != null) {
                int simState = Integer.parseInt(ob_phone.toString());
                if (simState == TelephonyManager.SIM_STATE_READY) {
                    isReady = true;
                }

            }
        } catch (Exception e) {

        }

        return isReady;
    }
}

Related Tutorials