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 getDeviceInfo(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    StringBuilder sb = new StringBuilder();
    sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
    sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
    sb.append("\nLine1Number = " + tm.getLine1Number());
    sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
    sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
    sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
    sb.append("\nNetworkType = " + tm.getNetworkType());
    sb.append("\nPhoneType = " + tm.getPhoneType());
    sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
    sb.append("\nSimOperator = " + tm.getSimOperator());
    sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
    sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
    sb.append("\nSimState = " + tm.getSimState());
    sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
    sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());

    return sb.toString();
}

From source file:ca.psiphon.PsiphonTunnel.java

private static String getDeviceRegion(Context context) {
    String region = "";
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        region = telephonyManager.getSimCountryIso();
        if (region == null) {
            region = "";
        }//from   w w  w .  java  2s . c  om
        if (region.length() == 0 && telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
            region = telephonyManager.getNetworkCountryIso();
            if (region == null) {
                region = "";
            }
        }
    }
    if (region.length() == 0) {
        Locale defaultLocale = Locale.getDefault();
        if (defaultLocale != null) {
            region = defaultLocale.getCountry();
        }
    }
    return region.toUpperCase(Locale.US);
}

From source file:android_network.hetnet.vpn_service.Util.java

public static boolean isInternational(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return (tm != null && tm.getSimCountryIso() != null
            && !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
}

From source file:eu.faircode.netguard.Util.java

public static boolean isNational(Context context) {
    try {//from w ww.j a va2  s  . c om
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return (tm != null && tm.getSimCountryIso() != null
                && tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
    } catch (Throwable ignored) {
        return false;
    }
}

From source file:eu.faircode.netguard.Util.java

public static boolean isEU(Context context) {
    try {/*from w  ww . j a  v  a2s .co m*/
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return (tm != null && isEU(tm.getSimCountryIso()) && isEU(tm.getNetworkCountryIso()));
    } catch (Throwable ignored) {
        return false;
    }
}

From source file:foo.fruitfox.evend.LoginActivity.java

private String getPhoneNumber() {
    String countryCode = "";
    TelephonyManager tMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    String mRawPhoneNumber = tMgr.getLine1Number();
    String countryISO = tMgr.getSimCountryIso().toUpperCase(Locale.ENGLISH);
    String[] countryCodeList = this.getResources().getStringArray(R.array.CountryCodes);
    String mPhoneNumber;//from  www. jav a 2 s.  c om

    if (mRawPhoneNumber.startsWith("+") == false) {
        for (int i = 0; i < countryCodeList.length; i++) {
            String[] countryCodePair = countryCodeList[i].split(",");
            if (countryCodePair[1].trim().equals(countryISO.trim())) {
                countryCode = countryCodePair[0];
                break;
            }
        }

        mPhoneNumber = "+" + countryCode + mRawPhoneNumber;
    } else {
        mPhoneNumber = mRawPhoneNumber;
    }

    return mPhoneNumber;
}

From source file:android_network.hetnet.vpn_service.Util.java

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
        sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                tm.getSimOperator()));//from  w ww .  j av  a  2s.c  om
    if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
        sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(),
                tm.getNetworkOperator()));

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        sb.append(String.format("Data saving %B\r\n", dataSaving(context)));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java

private void setSpinnerCountry(Spinner spinner) {
    TelephonyManager tel = (TelephonyManager) getApplicationContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    String country = tel.getSimCountryIso();
    Log.i(tag, "country: " + country);
    if (Text.isEmpty(country)) {
        spinner.setSelection(92); // India
        return;/*from w  ww. java 2  s  . c  om*/
    }
    CountryMap m = new CountryMap();
    Log.i(tag, "index: " + m.getIndex(country.toUpperCase()));
    spinner.setSelection(m.getIndex(country.toUpperCase()));
    Log.i(tag, "country: " + m.getCallingCode(country.toUpperCase()));
}

From source file:com.master.metehan.filtereagle.Util.java

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    sb.append(String.format("Type %s\r\n", getPhoneTypeName(tm.getPhoneType())));

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || !hasPhoneStatePermission(context)) {
        if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
            sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                    tm.getSimOperator()));
        if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
            sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(),
                    tm.getNetworkOperatorName(), tm.getNetworkOperator()));
    }/* w  w  w  . j  a  v a 2 s .  c o m*/

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n",
                !pm.isIgnoringBatteryOptimizations(context.getPackageName())));

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static Currency getLocalCurrency() {
    Currency result = null;/*from   www  . j  av  a 2 s  .  c  om*/
    TelephonyManager telephonyManager = (TelephonyManager) MyApplication.getInstance()
            .getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        try {
            String userCountry = telephonyManager.getNetworkCountryIso();
            if (TextUtils.isEmpty(userCountry)) {
                userCountry = telephonyManager.getSimCountryIso();
            }
            if (!TextUtils.isEmpty(userCountry)) {
                result = getSaveInstance(Currency.getInstance(new Locale("", userCountry)));
            }
        } catch (Exception e) {
            //fall back to currency from locale
        }
    }
    if (result == null) {
        try {
            //makeSure we know about the currency
            result = getSaveInstance(Currency.getInstance(Locale.getDefault()));
        } catch (IllegalArgumentException e) {
            result = Currency.getInstance("EUR");
        }
    }
    return result;
}