In my app, there is an ImageView that display an image from a URL.
I download the image using this method:
Bitmap bitmap=null;
URL imageUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
bitmap = decodeFile(f);
return bitmap;
This works only with URLs that has numbers or english letters and doesn't work with any other chars (like spaces):
Good URL: http://site.com/images/image.png
Bad URL: http://site.com/images/image 1.png
I tried to chage the URL encoding (URLEncoder.encode), but it changes the whole URL (incliding slashes, ect...).
Do I need to replace some chars after the encoding? or maybe there is a better way?
Thanks :)