Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to url encode in android?

I am using grid view for displaying image using xml parsing,i got some exception like

java.lang.IllegalArgumentException: Illegal character in path at index 80: http://www.theblacksheeponline.com/party_img/thumbspps/912big_361999096_Flicking Off Douchebag.jpg

How to solve this problem? I want to display all kind of url,anybody knows please give sample code for me.

Thanks All

like image 844
sivaraj Avatar asked Sep 17 '10 11:09

sivaraj


People also ask

How do I encode a URL?

Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

How do you add %20 to a URL?

Spaces are not allowed in URLs. They should be replaced by the string %20. In the query string part of the URL, %20 can be abbreviated using a plus sign (+).

What is %20 in the URL?

A space is assigned number 32, which is 20 in hexadecimal. When you see “%20,” it represents a space in an encoded URL, for example, http://www.example.com/products%20and%20services.html.

What is URL encode in Java?

Simply put, URL encoding translates special characters from the URL to a representation that adheres to the spec and can be correctly understood and interpreted.


1 Answers

URL encoding is done in the same way on android as in Java SE;

try {
    String url = "http://www.example.com/?id=123&art=abc";
    String encodedurl = URLEncoder.encode(url,"UTF-8");
    Log.d("TEST", encodedurl);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} 
like image 152
Cpt.Ohlund Avatar answered Oct 03 '22 04:10

Cpt.Ohlund