0

I have images on server named by email so when i try to download them on my application the @ symbol not shown on the path, is there anyway to stop escape this symbol ?

Example : Correct Path Http://www.xxxxx.com/a@a.com.jpg

Wrong Path Http://www.xxxxx.com/aa.com.jpg

I tried URL encode but its not useful in my case

Bitmap downloadFile(String fileUrl) {
    URL myFileUrl = null;
    Bitmap bmImg = null;
    try {
        myFileUrl = new URL(fileUrl);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        HttpURLConnection conn = (HttpURLConnection) myFileUrl
                .openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();

        bmImg = BitmapFactory.decodeStream(is);

        // imView.setImageBitmap(bmImg);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return bmImg;

}

1 Answers1

0

Try using the URLEncoder from Android SDK.

try {
    myFileUrl = new URL(java.net.URLEncoder.encode(fileUrl));
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

EDIT:

Just saw my mistake. That won't work because it's encoding the entire URL.

You have to separate the email address from the rest of the url like this.

    myFileUrl = new URL("http://www.xxxx.com/"+java.net.URLEncoder.encode(email));

Or alternatively, just replace the problem character.

    myFileUrl = new URL(fileUrl.replace("@","%40"));
Reactgular
  • 52,335
  • 19
  • 158
  • 208
  • Thank you, but i figured out the main problem, the server sent url with wrong backslashes (http:\/\/www.xxxx.com//) – user2448444 Jun 04 '13 at 07:00