Example usage for android.telephony TelephonyManager SIM_STATE_ABSENT

List of usage examples for android.telephony TelephonyManager SIM_STATE_ABSENT

Introduction

In this page you can find the example usage for android.telephony TelephonyManager SIM_STATE_ABSENT.

Prototype

int SIM_STATE_ABSENT

To view the source code for android.telephony TelephonyManager SIM_STATE_ABSENT.

Click Source Link

Document

SIM card state: no SIM card is available in the device

Usage

From source file:Main.java

public static boolean isSIMPresent(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT) {
        return false;
    } else/*  w w w. ja  va2 s .  c o  m*/
        return true;
}

From source file:Main.java

/**
 * Returns a constant indicating the state of the default SIM card.
 * @param sim_state "getSimState()"//from  w ww  .j a  va 2s .  c  om
 */
public static String getSimStateStr(int sim_state) {
    switch (sim_state) {
    case TelephonyManager.SIM_STATE_UNKNOWN://0
        return "SIM_STATE_UNKNOWN";
    case TelephonyManager.SIM_STATE_ABSENT://1
        return "SIM_STATE_ABSENT";
    case TelephonyManager.SIM_STATE_PIN_REQUIRED://2
        return "SIM_STATE_PIN_REQUIRED";
    case TelephonyManager.SIM_STATE_PUK_REQUIRED://3
        return "SIM_STATE_PUK_REQUIRED";
    case TelephonyManager.SIM_STATE_NETWORK_LOCKED://4
        return "SIM_STATE_NETWORK_LOCKED";
    case TelephonyManager.SIM_STATE_READY://5
        return "SIM_STATE_READY";
    default:
        return UNKNOWN;
    }
}

From source file:com.appsimobile.appsii.module.calls.CallLogLoader.java

public static String getCountry(TelephonyManager telephonyManager) {
    TelephonyManager tm = telephonyManager;
    if (tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT) {
        return Locale.getDefault().getCountry();
    }/*from w w w . ja v  a  2 s  . c o  m*/
    return tm.getSimCountryIso();
}

From source file:com.android.settings.sim.SimSelectNotification.java

@Override
public void onReceive(Context context, Intent intent) {
    final TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final int numSlots = telephonyManager.getSimCount();

    // Do not create notifications on single SIM devices or when provisioning i.e. Setup Wizard.
    // or User selection of fallback user preference is disabled.
    if (numSlots < 2 || !Utils.isDeviceProvisioned(context)
            || !SystemProperties.getBoolean("persist.radio.aosp_usr_pref_sel", false)) {
        Log.d(TAG, " no of slots " + numSlots + " provision = " + Utils.isDeviceProvisioned(context));
        return;//from   w  w  w .  j av a2s  .  c  om
    }

    // Cancel any previous notifications
    cancelNotification(context);

    // If sim state is not ABSENT or LOADED then ignore
    String simStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
    if (!(IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(simStatus)
            || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(simStatus))) {
        Log.d(TAG, "sim state is not Absent or Loaded");
        return;
    } else {
        Log.d(TAG, "simstatus = " + simStatus);
    }

    int state;
    for (int i = 0; i < numSlots; i++) {
        state = telephonyManager.getSimState(i);
        if (!(state == TelephonyManager.SIM_STATE_ABSENT || state == TelephonyManager.SIM_STATE_READY
                || state == TelephonyManager.SIM_STATE_UNKNOWN)) {
            Log.d(TAG, "All sims not in valid state yet");
            return;
        }
    }

    List<SubscriptionInfo> sil = subscriptionManager.getActiveSubscriptionInfoList();
    if (sil == null || sil.size() < 1) {
        Log.d(TAG, "Subscription list is empty");
        return;
    }

    // Clear defaults for any subscriptions which no longer exist
    subscriptionManager.clearDefaultsForInactiveSubIds();

    boolean dataSelected = SubscriptionManager
            .isUsableSubIdValue(SubscriptionManager.getDefaultDataSubscriptionId());
    boolean smsSelected = SubscriptionManager
            .isUsableSubIdValue(SubscriptionManager.getDefaultSmsSubscriptionId());

    // If data and sms defaults are selected, dont show notification (Calls default is optional)
    if (dataSelected && smsSelected) {
        Log.d(TAG, "Data & SMS default sims are selected. No notification");
        return;
    }

    // Create a notification to tell the user that some defaults are missing
    createNotification(context);

    if (sil.size() == 1) {
        // If there is only one subscription, ask if user wants to use if for everything
        Intent newIntent = new Intent(context, SimDialogActivity.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK);
        newIntent.putExtra(SimDialogActivity.PREFERRED_SIM, sil.get(0).getSimSlotIndex());
        context.startActivity(newIntent);
    } else if (!dataSelected) {
        // If there are mulitple, ensure they pick default data
        Intent newIntent = new Intent(context, SimDialogActivity.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DATA_PICK);
        context.startActivity(newIntent);
    }
}

From source file:com.fallahpoor.infocenter.fragments.SimFragment.java

private boolean isSimPresent() {

    TelephonyManager telephonyManager = (TelephonyManager) getActivity()
            .getSystemService(Context.TELEPHONY_SERVICE);

    return (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM
            && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT);

}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static boolean isSimMissing(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int simState = telephonyManager.getSimState();
    return simState == TelephonyManager.SIM_STATE_ABSENT || simState == TelephonyManager.SIM_STATE_UNKNOWN;
}

From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java

/**
 * sim??// ww w .j  a  v  a  2s. c om
 *
 * @param tm
 * @return
 */
private boolean checkSimCardState(TelephonyManager tm) {
    int simState = tm.getSimState();
    switch (simState) {
    case TelephonyManager.SIM_STATE_ABSENT:
        return false;
    case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
        return true;
    case TelephonyManager.SIM_STATE_PIN_REQUIRED:
        return true;
    case TelephonyManager.SIM_STATE_PUK_REQUIRED:
        return true;
    case TelephonyManager.SIM_STATE_READY:
        return true;
    case TelephonyManager.SIM_STATE_UNKNOWN:
        return false;
    default:
        return false;
    }
}

From source file:com.p2p.misc.DeviceUtility.java

public int simPresent() {

    TelephonyManager tManager = (TelephonyManager) mactivity.getSystemService(Context.TELEPHONY_SERVICE);

    int state = TelephonyManager.SIM_STATE_ABSENT;

    /*//from w  ww  .  ja v a  2  s .  c o m
       * if (tManager.getSimState() != state) { // sim present } else { // sim
     * absent }
     */

    return state;
}

From source file:edu.polyu.screamalert.SoundProcessing.java

private static void sendSMS() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext);
    Boolean enableSMS = prefs.getBoolean("enableSMS", false);
    String phoneNumber = prefs.getString("phoneNumber", null);
    TelephonyManager phoneMgr = (TelephonyManager) thisContext.getSystemService(Context.TELEPHONY_SERVICE);
    if (enableSMS == true && phoneNumber != null && phoneNumber.trim().length() > 0
            && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNumber, null, "Scream detected. Longitude: " + gps.getLongitude()
                + "; Latitude: " + gps.getLatitude() + ". Please try to contact the mobile user", null, null);
    }//from   ww w . j  a v  a2 s . c  om
}

From source file:edu.polyu.screamalert.SoundProcessing.java

private static void callPhone() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext);
    String phoneNumber = prefs.getString("phoneNumber", null);
    Boolean enableCall = prefs.getBoolean("enableCall", false);
    if (phoneNumber != null && enableCall) {
        if (phoneNumber.trim().length() > 0) { // Avoid empty string or white spaces in the preference field
            TelephonyManager phoneMgr = (TelephonyManager) thisContext
                    .getSystemService(Context.TELEPHONY_SERVICE);
            if (phoneMgr.getCallState() == TelephonyManager.CALL_STATE_IDLE
                    && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                callIntent.setData(Uri.parse("tel:" + phoneNumber));
                Exchanger.thisContext.startActivity(callIntent);
            }// w w w  . j  a  v a 2 s .  c o  m
        }
    }
}