title: Retrieveing saved address from phonebook by using a pick intent
body: <p>I want to pick a contact from phone book using intent and selected contact should also contain respective city and state (if saved by user).</p>
  
  <p>Here is what I am trying for past few days:</p>
  
  <pre><code>private void accessContacts() {
   Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
      intent.setDataAndType(ContactsContract.Contacts.CONTENT_URI,
          ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
      startActivityForResult(intent, PICK_CONTACT);
    } 
  
  @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      switch (requestCode) {
        case PICK_CONTACT:
          if (resultCode == Activity.RESULT_OK) {
            Uri contactData = data.getData();
            String[] projection = {
                ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Phone.NUMBER
            };
            String name = null;
            String phoneNumber = null;
            String city = null;
            String state = null;
  
            Cursor c =
                getActivity().getContentResolver().query(contactData, null, null, null, null);
            if (c != null) {
              if (c.moveToFirst()) {
                int nameIdx = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
                int phoneNumberIdx = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
                name = c.getString(nameIdx);
                phoneNumber = c.getString(phoneNumberIdx);
  
                String id = c.getString(c.getColumnIndex(ContactsContract.PhoneLookup._ID));
  
                String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND "
                    + ContactsContract.Data.MIMETYPE + " = ?";
                String[] addrWhereParams = new String[]{id,
                    ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
                Cursor addrCur = getActivity().getContentResolver()
                    .query(ContactsContract.Data.CONTENT_URI,
                    null, addrWhere, addrWhereParams, null);
  
                if (addrCur.moveToFirst()) {
                  city = addrCur.getString(
                      addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
                  state = addrCur.getString(
                      addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
                }
                addrCur.close();
  
              }
              c.close();
            }
  
            if (name == null) {
              name = "No Name";
            }
  
            if (TextUtils.isEmpty(phoneNumber) || phoneNumber.length() &lt; 10) {
              handleAddConnectionError(getContext().getString(R.string.invalid_phone_number));
              return;
            }
  
            Phonenumber.PhoneNumber number =
                Utils.validateMobileNumber2(phoneNumber, Device.getCountryCode(getActivity()));
            if (number == null) {
              handleAddConnectionError(getContext().getString(R.string.invalid_phone_number));
              return;
            }
  
  
            this.moveToCategoryPage(name, String.valueOf(number.getNationalNumber()),
                Utils.getCountryCodeWithPlusSign(number), false, null,
                city, state);
          }
          break;
      }
  
    }
  </code></pre>
  
  <p>While removing/changing this:</p>
  
  <blockquote>
    <p>intent.setDataAndType(ContactsContract.Contacts.CONTENT_URI,
            ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);</p>
  </blockquote>
  
  <p>it throws exception.</p>
  
  <p><strong><em>How can I get saved address from pick intent?</em></strong></p>