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:org.lumicall.android.sip.RegisterAccount.java

private String getMyPhoneNumber() {
    TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String num = mTelephonyMgr.getLine1Number();

    // MSISDN should not have a +, but some phones return it with a +
    // We want to see a +
    if (num != null && num.length() > 0 && !(num.charAt(0) == '+'))
        num = "+" + num;

    /* if(num == null || num.length() == 0) {
       PhoneHelper ph = new PhoneHelper();
       ph.init(this);//w  w w.j  av a 2 s.  c o m
       num = ph.getLine1Number();
    } */

    if (num == null || num.length() == 0)
        num = "+" + getCountryCode(mTelephonyMgr.getSimCountryIso());

    return num;
}

From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java

public String GetCountryZipCode() {
    String CountryID = "";
    String CountryZipCode = "";
    TelephonyManager manager = (TelephonyManager) mcontext.getSystemService(Context.TELEPHONY_SERVICE);
    // getNetworkCountryIso
    CountryID = manager.getSimCountryIso().toUpperCase();
    String[] rl = mcontext.getResources().getStringArray(R.array.CountryCodes);
    for (int i = 0; i < rl.length; i++) {
        String[] g = rl[i].split(",");
        if (g[1].trim().equals(CountryID.trim())) {
            CountryZipCode = g[0];//  w w w. jav a  2s.co m
            break;
        }
    }
    return CountryZipCode;
}

From source file:org.kontalk.ui.NumberValidation.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.number_validation);
    setupToolbar(false, false);/*from ww w  .j ava 2 s .  c om*/

    mAccountManager = AccountManager.get(this);
    mHandler = new Handler();

    lbm = LocalBroadcastManager.getInstance(getApplicationContext());

    final Intent intent = getIntent();
    mFromInternal = intent.getBooleanExtra(PARAM_FROM_INTERNAL, false);

    mNameText = (EditText) findViewById(R.id.name);
    mCountryCode = (Spinner) findViewById(R.id.phone_cc);
    mPhone = (EditText) findViewById(R.id.phone_number);
    mValidateButton = (Button) findViewById(R.id.button_validate);

    // populate country codes
    final CountryCodesAdapter ccList = new CountryCodesAdapter(this, android.R.layout.simple_list_item_1,
            android.R.layout.simple_spinner_dropdown_item);
    PhoneNumberUtil util = PhoneNumberUtil.getInstance();
    Set<String> ccSet = getSupportedRegions(util);
    for (String cc : ccSet)
        ccList.add(cc);

    ccList.sort(new Comparator<CountryCodesAdapter.CountryCode>() {
        public int compare(CountryCodesAdapter.CountryCode lhs, CountryCodesAdapter.CountryCode rhs) {
            return lhs.regionName.compareTo(rhs.regionName);
        }
    });
    mCountryCode.setAdapter(ccList);
    mCountryCode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ccList.setSelected(position);
        }

        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub
        }
    });

    // FIXME this doesn't consider creation because of configuration change
    PhoneNumber myNum = NumberValidator.getMyNumber(this);
    if (myNum != null) {
        CountryCode cc = new CountryCode();
        cc.regionCode = util.getRegionCodeForNumber(myNum);
        if (cc.regionCode == null)
            cc.regionCode = util.getRegionCodeForCountryCode(myNum.getCountryCode());
        mCountryCode.setSelection(ccList.getPositionForId(cc));
        mPhone.setText(String.valueOf(myNum.getNationalNumber()));
    } else {
        final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        final String regionCode = tm.getSimCountryIso().toUpperCase(Locale.US);
        CountryCode cc = new CountryCode();
        cc.regionCode = regionCode;
        cc.countryCode = util.getCountryCodeForRegion(regionCode);
        mCountryCode.setSelection(ccList.getPositionForId(cc));
    }

    // listener for autoselecting country code from typed phone number
    mPhone.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // unused
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // unused
        }

        @Override
        public void afterTextChanged(Editable s) {
            syncCountryCodeSelector();
        }
    });

    // configuration change??
    RetainData data = (RetainData) getLastCustomNonConfigurationInstance();
    if (data != null) {
        synchronized (this) {
            // sync starter was queued, we can exit
            if (data.syncing) {
                delayedSync();
            }

            mValidator = data.validator;
            if (mValidator != null)
                mValidator.setListener(this);
        }
        if (data.progressMessage != null) {
            setProgressMessage(data.progressMessage, true);
        }
    }
}

From source file:org.deviceconnect.android.deviceplugin.irkit.IRKitManager.java

/**
 * ??.//w  ww. j a  v  a2s  .c  o  m
 * 
 * @param context ??????
 */
public void init(final ContextWrapper context) {
    mAPIKey = context.getString(R.string.apikey);

    TelephonyManager tm = getTelephonyManager(context);
    mCountryCode = tm.getSimCountryIso().toUpperCase(Locale.ENGLISH);
}

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

public static boolean isInternational(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && hasPhoneStatePermission(context)) {
        int dataSubId;
        try {//from w  w  w.  ja v a 2  s .co  m
            dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1);
        } catch (Throwable ignored) {
            dataSubId = -1;
        }
        if (dataSubId >= 0) {
            SubscriptionManager sm = SubscriptionManager.from(context);
            SubscriptionInfo si = sm.getActiveSubscriptionInfo(dataSubId);
            if (si != null && si.getCountryIso() != null)
                try {
                    Method getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription",
                            int.class);
                    getNetworkCountryIso.setAccessible(true);
                    String networkCountryIso = (String) getNetworkCountryIso.invoke(tm, dataSubId);
                    Log.d(TAG, "SIM=" + si.getCountryIso() + " network=" + networkCountryIso);
                    return !si.getCountryIso().equals(networkCountryIso);
                } catch (Throwable ex) {
                    Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    sendCrashReport(ex, context);
                }
        }
    }

    return (tm == null || tm.getSimCountryIso() == null
            || !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
}

From source file:com.softcoil.ApnDefaults.java

/**
 * This method provides a means for clients to report new, good APN connection parameters
 * to a central repository so that they can be integrated with this class and shared with
 * the public.// ww w.j  a va 2  s.co  m
 *
 * It contains protections so that new ApnParameters are only reported to the server the first
 * time this method is called. In addition, it uses a short connection timeout so it can be
 * safely called from your current worker thread without worry that it will unnecessarily
 * delay your process.
 *
 * It should be called immediately after successfully sending a MMS message. Example:<br/>
 *  <pre>
 *  //Send your MMS using whatever method you currently use.
 *  byte[] response = myMmsHttpPost(mmscUrl, mmsProxy, mmsProxyPort, sendReqPdu);
 *
 *  //Parse the response.
 *  SendConf sendConf = (SendConf) new PduParser(response).parse();
 *
 *  //Check to see if the response was success.
 *  if(sendConf != null && sendConf.getResponseStatus() == PduHeaders.RESPONSE_STATUS_OK) {
 *      //Report the ApnParameters used for the post.
 *      ApnParameters parameters = new ApnParameters(mmscUrl, mmsProxy, mmsProxyPort);
 *      ApnDefaults.reportApnData(context, parameters);
 *  }
 *
 *  //Continue your process.
 *  ...
 *  </pre>
 *
 *  In order for this class to be useful we must collect data from as many working
 *  configurations as possible. Adding a call to this method after a successful MMSC operation
 *  in your app will help us all to provide a good MMS experience to our users.
 *
 * @param context The current context.
 * @param apnParameters The known good ApnParameters to report.
 */
public static void reportApnData(Context context, ApnParameters apnParameters) {

    if (apnParameters == null)
        return;

    String apnData = apnParameters.getMmscUrl() + "|" + apnParameters.getProxyAddress() + "|"
            + apnParameters.getProxyPort();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String previousApnData = prefs.getString(PREF_KEY_LAST_APN_REPORT, null);

    if (!apnData.equals(previousApnData)) {

        //Save new apn data
        prefs.edit().putString(PREF_KEY_LAST_APN_REPORT, apnData).apply();

        //Report new apn data
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String networkOperator = tm.getNetworkOperator();
        String networkOperatorName = tm.getNetworkOperatorName();
        String simOperator = tm.getSimOperator();
        String simOperatorName = tm.getSimOperatorName();

        //Create HttpClient
        AndroidHttpClient client = AndroidHttpClient.newInstance("ApnDefaults/0.1");
        HttpParams params = client.getParams();
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        HttpConnectionParams.setConnectionTimeout(params, 1 * 1000); //Set timeout to wait for a connection.
        HttpConnectionParams.setSoTimeout(params, 1 * 1000); //Set timeout to wait for a response.
        try {
            StringBuffer uriString = new StringBuffer(REPORT_URL).append("?")
                    //Report the MMSC connection used.
                    .append("apnData=").append(URLEncoder.encode(apnData, "UTF-8"))
                    //SIM and Network data are reported to enable determining which
                    //parameters work under which circumstances.
                    .append("&simOperator=").append(URLEncoder.encode(simOperator, "UTF-8"))
                    .append("&simOperatorName=").append(URLEncoder.encode(simOperatorName, "UTF-8"))
                    .append("&simCountry=").append(URLEncoder.encode(tm.getSimCountryIso(), "UTF-8"))
                    .append("&networkOperator=").append(URLEncoder.encode(networkOperator, "UTF-8"))
                    .append("&networkOperatorName=").append(URLEncoder.encode(networkOperatorName, "UTF-8"))
                    .append("&networkCountry=").append(URLEncoder.encode(tm.getNetworkCountryIso(), "UTF-8"));

            URI uri = new URI(uriString.toString());

            //Send request
            client.execute(new HttpGet(uri));
            client.close();
        } catch (Exception e) {
        }
    }
}