Breaking News
Home / Android / Android Snippets / How do you encode url in Android?

How do you encode url in Android?

Snippet

Encoding URL is very straightforward, simply call the encode method of the URLEncoder class on the String data that you want to encode.

  1. try {  
  2.   String url = "http://www.yoursite.com/blah";
  3.   String queryString = "param=1&value=2";  
  4.  
  5.   String encodedQueryString = URLEncoder.encode(queryString,"UTF-8");
  6.  
  7.    encodedUrl = url + "?" + encodedQueryString;
  8.  
  9.    Log.d("Enc URL: " + encodedurl);
  10.  }
  11.  catch (UnsupportedEncodingException e)
  12.  {
  13.   Log.e("Exception: " + e.getMessage());
  14.  
  15.  }
[pb_builder]

Check Also

How to check if an Android device can connect to Internet?

The following code snippet shows how to check if an Android device can connect to …

Leave a Reply