Example usage for android.telephony TelephonyManager getSimCountryIso

List of usage examples for android.telephony TelephonyManager getSimCountryIso

Introduction

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

Prototype

public String getSimCountryIso() 

Source Link

Document

Returns the ISO-3166 country code equivalent for the SIM provider's country code.

Usage

From source file:Main.java

public static String getCountryISOFromSimCard(final Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getSimCountryIso();
}

From source file:Main.java

public static String getRegionCodeFromSIM(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getSimCountryIso();
}

From source file:Main.java

/**
 * Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
 *
 * @param context Context reference to get the TelephonyManager instance from
 * @return country code or null/* www . ja  va 2 s  .c o  m*/
 */
public static String getDeviceCountry(Context context) {
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        final String simCountry = tm.getSimCountryIso();
        if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
            return simCountry.toLowerCase(Locale.US);
        } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
            String networkCountry = tm.getNetworkCountryIso();
            if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
                return networkCountry.toLowerCase(Locale.US);
            }
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

public static String getCountry(Context ctx) {
    TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    Locale locale = Locale.getDefault();
    return tm.getSimState() == TelephonyManager.SIM_STATE_READY
            ? tm.getSimCountryIso().toLowerCase(Locale.getDefault())
            : locale.getCountry().toLowerCase(locale);
}

From source file:uk.ac.ucl.excites.sapelli.shared.util.android.DeviceControl.java

public static String getSimCountryISOCode(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getSimCountryIso();
}

From source file:tw.com.ksmt.cloud.libs.Utils.java

/**
 * Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
 *
 * @param context Context reference to get the TelephonyManager instance from
 * @return country code or null/*w  ww  .j a  va 2 s  .c  om*/
 */
public static String getCountryBySIM(Context context) {
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        final String simCountry = tm.getSimCountryIso();
        if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
            return simCountry.toUpperCase(Locale.US);
        } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
            String networkCountry = tm.getNetworkCountryIso();
            if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
                return networkCountry.toUpperCase(Locale.US);
            }
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

public static String queryDevicePhone(Context context) {
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (manager != null) {
        operatorCode = manager.getNetworkOperator();
        if (operatorCode == null || operatorCode.length() == 0)
            operatorCode = manager.getSimOperator();
        isoCountryCode = manager.getNetworkCountryIso();
        if (isoCountryCode == null || isoCountryCode.length() == 0)
            isoCountryCode = manager.getSimCountryIso();
        if (isoCountryCode == null || isoCountryCode.length() == 0)
            isoCountryCode = context.getResources().getConfiguration().locale.getCountry();
    }//ww  w.  j  a v a2 s . co m
    return manager.getLine1Number();
}

From source file:com.quantcast.measurement.service.QCPolicy.java

public static QCPolicy getQuantcastPolicy(Context context, String apiKey, String networkCode,
        String packageName, boolean kidDirected) {
    Uri.Builder builder = Uri.parse(QCUtility.addScheme(POLICY_REQUEST_BASE_WITHOUT_SCHEME)).buildUpon();
    builder.appendQueryParameter(POLICY_REQUEST_API_VERSION_PARAMETER, QCUtility.API_VERSION);
    builder.appendQueryParameter(POLICY_REQUEST_DEVICE_TYPE_PARAMETER, POLICY_REQUEST_DEVICE_TYPE);

    String mcc = null;/* ww  w  .j  a  va2s  . co m*/
    try {
        TelephonyManager tel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (tel != null) {
            mcc = tel.getNetworkCountryIso();
            if (mcc == null) {
                mcc = tel.getSimCountryIso();
            }
        }
    } catch (SecurityException ignored) {
    }

    if (mcc == null) {
        mcc = Locale.getDefault().getCountry();
    }
    if (mcc != null) {
        builder.appendQueryParameter(POLICY_REQUEST_DEVICE_COUNTRY, mcc);
    }

    if (apiKey != null) {
        builder.appendQueryParameter(POLICY_REQUEST_API_KEY_PARAMETER, apiKey);
    } else {
        builder.appendQueryParameter(POLICY_REQUEST_NETWORK_CODE_PARAMETER, networkCode);
        builder.appendQueryParameter(POLICY_REQUEST_PACKAGE_PARAMETER, packageName);
    }

    if (kidDirected) {
        builder.appendQueryParameter(POLICY_REQUEST_KID_DIRECTED_PARAMETER, "YES");
    }

    Uri builtURL = builder.build();
    if (builtURL != null) {
        return new QCPolicy(context, builtURL.toString());
    } else {
        QCLog.e(TAG, "Policy URL was not built correctly for some reason.  Should not happen");
        return null;
    }
}

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();
    }//  w  ww.  ja v a 2s .c o m
    return tm.getSimCountryIso();
}

From source file:Main.java

public static String getPhoneStatus(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "honeType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
    return str;//from w ww. j av a2 s . co  m
}