I am trying to download image from server. Few are downloading and few and creating problem. I don't know why.
I have downloaded and show image to user on the same location. Here is the file which is able to download.
When I am trying to download following image. This image is opening in browser but not downloading in android
Its give exception
java.io.FileNotFoundException: http://www.mongreldog.co.nz/unilogo/Twitter-Ryan_Giggs_Imogen_Thomas_Guard-Footballer_Affair_UK_Manchester United_M_785.jpg at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521) at src.com.mongreldog.appsupport.Utils.downloadImage(Utils.java:77) at src.com.mongreldog.ViewFullCompAndCommentActivity$3.performInBackground(ViewFullCompAndCommentActivity.java:607) at src.com.mongreldog.appsupport.HeavyWorker.doInBackground(HeavyWorker.java:44) at src.com.mongreldog.appsupport.HeavyWorker.doInBackground(HeavyWorker.java:1) at android.os.AsyncTask$2.call(AsyncTask.java:185)
Here is my code.
public static Bitmap downloadImage(String imageURLStr) {
Bitmap bitmap = null;
InputStream in = null;
try {
URL url = new URL(imageURLStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
in = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (SocketTimeoutException e) {
bitmap = null;
e.printStackTrace();
} catch (IOException e) {
bitmap = null;
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
bitmap = null;
} catch (OutOfMemoryError e) {
e.printStackTrace();
bitmap = null;
}
return bitmap;
}