title: Country code is not getting from country code picker in Android
body: <p>I am developing an signup activity in android app. I want show the country telephone code(get the country from device). It may show the list of countries containing with flag, country telephone code, country name. I get the code of country code picker from <a href="https://github.com/mukeshsolanki/country-picker-android" rel="nofollow noreferrer">https://github.com/mukeshsolanki/country-picker-android</a> . It contain the complete code. I want to set the default country is in the phone. </p>
  
  <pre><code>TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
      String countryCodeValue = tm.getNetworkCountryIso();
      System.out.println("country = "+country);
  </code></pre>
  
  <p>When i using this code i get the country code "in". But i want to display telephone code and flag, name. When i open the screen. I want to display it automatically.</p>
  
  <p>My code is shown below</p>
  
  <p>Main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:background="@color/colorBackground"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fitsSystemWindows="true"&gt;
  
  &lt;LinearLayout
      android:layout_gravity="center_vertical"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingTop="56dp"
      android:paddingLeft="24dp"
      android:paddingRight="24dp"&gt;
  
      &lt;ImageView
          android:background="@drawable/logo"
          android:layout_gravity="center_horizontal"
          android:layout_width="150dp"
          android:layout_height="150dp" /&gt;
  
  
      &lt;Button
          android:text="Country"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/buttonCountry" /&gt;
  
      &lt;Spinner
          android:id="@+id/spinner1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:backgroundTint="#d11f08"
          android:entries="@array/android_dropdown_arrays"
          android:padding="5dp"  /&gt;
  
      &lt;android.support.design.widget.TextInputLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="8dp"
          android:layout_marginBottom="8dp"&gt;
          &lt;EditText android:id="@+id/editTextPhone"
              android:layout_width="match_parent"
              android:layout_height="44dp"
              android:inputType="phone"
              android:hint="Password"/&gt;
      &lt;/android.support.design.widget.TextInputLayout&gt;
  
      &lt;android.support.v7.widget.AppCompatButton
          android:id="@+id/buttonSubmit"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@color/colorPrimary"
          android:textColor="@color/colorAccent"
          android:layout_marginTop="24dp"
          android:layout_marginBottom="24dp"
          android:padding="12dp"
          android:text="Login"/&gt;
  
  
  
  &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>Main.Activity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  EditText editText;
  Button button;
  Button buttonCountry;
  
  private Spinner spinner1;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  
      editText = (EditText) findViewById(R.id.editTextPhone);
  
      button = (Button) findViewById(R.id.buttonSubmit);
  
      buttonCountry = (Button) findViewById(R.id.buttonCountry);
      spinner1 = (Spinner) findViewById(R.id.spinner1);
  
      TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
      String countryCodeValue = tm.getNetworkCountryIso();
      System.out.println("country = "+countryCodeValue);
      //String mPhoneNumber = tm.getLine1Number();  //not getting phone number
      //System.out.println("phone no = "+mPhoneNumber);
  
  
  
      buttonCountry.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              spinner1.setOnItemSelectedListener(new ItemSelectedListener());
  
              final CountryPicker picker = CountryPicker.newInstance("Select Country");
              picker.show(getSupportFragmentManager(), "COUNTRY_PICKER");
              picker.setListener(new CountryPickerListener() {
                  @Override
                  public void onSelectCountry(String name, String code, String dialCode, int flagDrawableResID) {
                      // Implement your code here
  
                      Log.d("LOGTAG", "output1 : name = "+name+" code = "+code+" dialcode = "+dialCode+" flag = "+flagDrawableResID);
                      picker.dismiss();
                  }
              });
          }
      });
  
  
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
          }
      });
  
  
  }
  
  public class ItemSelectedListener implements AdapterView.OnItemSelectedListener {
      //get strings of first item
      String firstItem = String.valueOf(spinner1.getSelectedItem());
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) {
          if (firstItem.equals(String.valueOf(spinner1.getSelectedItem()))) {
              // ToDo when first item is selected
          } else {
              Toast.makeText(parent.getContext(),
                      "You have selected : " + parent.getItemAtPosition(pos).toString(),
                      Toast.LENGTH_LONG).show();
              // Todo when item is selected by the user
          }
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; arg) {
  
      }
  
  }
  }
  </code></pre>
  
  <p>Reference : <a href="https://github.com/hbb20/CountryCodePickerProject" rel="nofollow noreferrer">https://github.com/hbb20/CountryCodePickerProject</a></p>