0

I am downloading images from URL, but there are spaces in URL so its skipping thoses URL. I have gone through several arcticles, which mentioned replace space with %20 or +, both the approach are not working. So what are the alternatives now.

    Log.i("CountryFlagThumb", VArray.get(2).replaceAll(" ", "%20")); 

    http://id8lab.net/WorldNewsApp/flags/United Arab Emirates.png

Thanks

3
  • what was the issue? how do you handle it? any error messages? Commented May 24, 2012 at 6:34
  • no images dont get downloaded, thats it. Commented May 24, 2012 at 6:36
  • 1
    Post the code which downloads images. Commented May 24, 2012 at 6:37

3 Answers 3

4

You don't encode the entire URL, only parts of it that come from "unreliable sources".

String data = URLEncoder.encode("United Arab Emirates.png", "utf-8");
String url = "http://id8lab.net/WorldNewsApp/flags/" + data;
Sign up to request clarification or add additional context in comments.

Comments

1

You just Encode your url like

String url =Uri.encode("http://id8lab.net/WorldNewsApp/flags/United Arab Emirates.png")

Hope this will help.

Comments

0

To download image from url use the following,

HttpGet httpRequest = new HttpGet(URI.create(path) );
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
Bitmap bmp = BitmapFactory.decodeStream(bufHttpEntity.getContent());
httpRequest.abort();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.