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:net.kidlogger.kidlogger.KLService.java

public void runRoamingEvent() {
    new Thread(new Runnable() {
        public void run() {
            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            try {
                String country = tm.getNetworkCountryIso();
                String operator = tm.getNetworkOperatorName();
                sync.writeLog(".htm", Templates.getRoamingInfo(country.toUpperCase(Locale.US), operator));
            } catch (Exception e) {
                app.logError(CN + "runRoamingEvent", e.toString());
            }//from  w  w w .j  a  va2  s  .  c om
        }
    }).start();
}

From source file:com.sonetel.ui.SipHome.java

private void postStartSipService() {
    // If we have never set fast settings
    //DBAdapter db = new DBAdapter(this);
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (CustomDistribution.showFirstSettingScreen()) {
        if (!prefProviderWrapper.getPreferenceBooleanValue(PreferencesWrapper.HAS_ALREADY_SETUP, false)) {

            //ContentValues initialValues = new ContentValues(); 

            for (int i = 1; i <= 52; i++) {
                //initialValues = AccessNumbers.getContentValues(i);
                getContentResolver().insert(SipProfile.ACCESS_URI, AccessNumbers.getContentValues(i));

                //db1.insert(db.databaseHelper.ACCESS_NUMS_TABLE_NAME, null, initialValues);
            }//  w  ww .  j ava2  s.com

        }

        prefProviderWrapper.setPreferenceBooleanValue(prefWrapper.ACCESS_NUM_ALREADY_FETCHED, true);// yuva should be true

        prefWrapper.setSimId(tm.getSubscriberId());
        Location_Finder locFinder = new Location_Finder(getBaseContext());
        prefWrapper.setTelCountryCode(locFinder.getTelContryCode());
        prefWrapper.setCurrentLocation(tm.getNetworkCountryIso());

        //PrefsLogic.setCallthruNumber(getBaseContext());

    } else {
        boolean doFirstParams = !prefProviderWrapper
                .getPreferenceBooleanValue(PreferencesWrapper.HAS_ALREADY_SETUP, false);
        prefProviderWrapper.setPreferenceBooleanValue(PreferencesWrapper.HAS_ALREADY_SETUP, true);
        if (!tm.getSubscriberId().equalsIgnoreCase(prefWrapper.getSimId())) {
            //final DBAdapter db = new DBAdapter(this);
            final EditText input = new EditText(this);

            new AlertDialog.Builder(this)

                    .setTitle("New SIM: Please enter new mobile number")

                    //.setMessage("Please enter your new mobile number in Sign in screen") 

                    .setIcon(R.drawable.ic_wizard_sonetel)

                    .setView(input)

                    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            String mobile = input.getText().toString();

                            int nbrOfAccount = doWeHaveAccount();
                            SipProfile account = new SipProfile();
                            if (nbrOfAccount != 0) {
                                account = SipProfile.getProfileFromDbId(getActivity(), 1,
                                        DBProvider.ACCOUNT_FULL_PROJECTION);
                                account.mobile_nbr = mobile;
                                getContentResolver().update(
                                        ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, 1),
                                        account.getDbContentValues(), null, null);
                            }

                            TelephonyManager tm = (TelephonyManager) getSystemService(
                                    Context.TELEPHONY_SERVICE);

                            prefWrapper.setSimId(tm.getSubscriberId());

                            if (mobile.length() < 8 && !mobile.startsWith("+")) {
                                Toast.makeText(getBaseContext(),
                                        "Invalid mobile number. Please enter +MOBILENUMBER in the international format",
                                        Toast.LENGTH_LONG).show();
                            }
                        }

                        private Context getActivity() {
                            // TODO Auto-generated method stub
                            return null;
                        }
                    })

                    .show();
        }
        if (doFirstParams) {
            prefProviderWrapper.resetAllDefaultValues();
        }
    }

    // If we have no account yet, open account panel,
    if (!hasTriedOnceActivateAcc && isInternetAvail) {
        int accountCount = 0;

        accountCount = doWeHaveAccount();

        if (accountCount == 0) {
            Intent accountIntent = null;
            WizardInfo distribWizard = CustomDistribution.getCustomDistributionWizard();
            if (distribWizard != null) {
                accountIntent = new Intent(this, BasePrefsWizard.class);
                accountIntent.putExtra(SipProfile.FIELD_WIZARD, distribWizard.id);
            } // else {
              //   accountIntent = new Intent(this, AccountsEditList.class);
              // }

            if (accountIntent != null) {
                accountIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(accountIntent);
                hasTriedOnceActivateAcc = true;
                return;
            }
        }
        hasTriedOnceActivateAcc = false;
    }
}

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./*from  ww  w.  ja va2 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) {
        }
    }
}