I have an app that loads images into bitmaps using a URL and recently got an email from a user with Android 2.2.1 who has been having trouble with some images not loading. I've tried looking around and can't seem to find any connection between the images that don't load. Furthermore, sometimes images that wouldn't load for her will start working again like nothing was wrong. I've never heard of this problem with any later versions of Android, so I would think it's an issue specific to 2.2.1. If anyone can explain to me what's going wrong and (if possible) how to fix it I would really appreciate it.
Here is the relevant code:
public class htmlGrabber extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
try {
return getHtml();
}
catch (IOException e) {
problem();
return null;
}
}//end of doInBackground
@Override
protected void onPostExecute(String result){
Loading.fa.finish();
shared_preferences=getSharedPreferences("shared_preferences_test", MODE_PRIVATE);
shared_preferences_editor = shared_preferences.edit();
shared_preferences_editor.putString("url_key", current);
shared_preferences_editor.commit();
TouchImageView img = (TouchImageView) findViewById(R.id.img);
img.setImageBitmap(bitmap);
}
}
public String getHtml() throws IllegalStateException, IOException{
//gets html from the url stored in current, then parses through it and extracts the image url, then converts
//it into a bitmap image
String html = "";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(current);
HttpResponse response = client.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
str.append(line);
}
in.close();
html = str.toString();
/* Edited out the code that parses through the HTML looking for the image URL. The image URL is stored in the string "link"
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(link).getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return html;
}//end of getHtml
}//end of htmlGrabber
If you need anything clarified please let me know!