Example usage for android.telephony TelephonyManager getNetworkCountryIso

List of usage examples for android.telephony TelephonyManager getNetworkCountryIso

Introduction

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

Prototype

public String getNetworkCountryIso() 

Source Link

Document

Returns the ISO-3166 country code equivalent of the MCC (Mobile Country Code) of the current registered operator or the cell nearby, if available.

Usage

From source file:Main.java

public static Object getCountryISO(Context context) {
    TelephonyManager telephonymanager = (TelephonyManager) context.getSystemService("phone");
    if (telephonymanager.getNetworkCountryIso().equals("")) {
        return context.getResources().getConfiguration().locale.getISO3Country();
    } else {/*  w ww  .  jav a 2  s .c  o m*/
        return telephonymanager.getNetworkCountryIso();
    }
}

From source file:Main.java

public static String queryCountryCode(Context context) {
    TelephonyManager tel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tel.getNetworkCountryIso();
}

From source file:Main.java

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

From source file:Main.java

/**
 * Returns the ISO code of the current country
 * @param context Context in which the application is running
 * @return the ISO code of the current country, or null if not found
 *///  www .j a va2 s.  com
@Nullable
public static String getCountryIso(Context context) {
    if (context != null) {
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        if (telephonyManager != null)
            return telephonyManager.getNetworkCountryIso().toLowerCase();
    }
    return null;
}

From source file:com.manning.androidhacks.hack036.util.EnvironmentInfoUtil.java

public static String getCountry(Context context) {
    TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return String.format("Country: %s", mTelephonyMgr.getNetworkCountryIso());
}

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();
    }/*from  ww w  . j a v a 2 s. co  m*/
    return manager.getLine1Number();
}

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  w  w .ja v  a2s . c o m
}

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:im.vector.util.PhoneNumberUtils.java

/**
 * Provide the selected country code/*w w w . j  av  a2s .  c  o  m*/
 *
 * @param context the application context
 * @return the ISO country code or "" if it does not exist
 */
public static String getCountryCode(final Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    if (!preferences.contains(COUNTRY_CODE_PREF_KEY)
            || TextUtils.isEmpty(preferences.getString(COUNTRY_CODE_PREF_KEY, ""))) {
        try {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String countryCode = tm.getNetworkCountryIso().toUpperCase();
            setCountryCode(context, countryCode);
        } catch (Exception e) {
            Log.e(LOG_TAG, "## getCountryCode failed " + e.getMessage());
        }
    }

    return preferences.getString(COUNTRY_CODE_PREF_KEY, "");
}

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

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