title: UTF-8 conversion in Android?
body: <p>I am encountering a problem that I need to call a web service. I just need to generate a UTF-8 encoded url string. Because the parameter may contain spaces, I am using below piece of code to encode to utf-8:</p>
  
  <pre><code>public String encodeUTF(String str) {
  
          try {
              byte[] utf8Bytes = str.getBytes("UTF-8");
  
              String encodedStr = new String(utf8Bytes, "UTF-8");
  
              return encodedStr;
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          }
          return str;
      }
  </code></pre>
  
  <p>But still I am getting the same value. Because of this I am getting illegal argument exception while calling the service. Any ideas?</p>