How to parse this url
http://ioe.edu.np/exam/notices/8560Result%20Diploma%20I_I.jpg
correctly so that it can be used as source for imageview. I have tried encoding it using Uri.encode() but that didn't help.
Below is the code that I am refering to load image from url. Got it from Android, Make an image at a URL equal to ImageView's image
public class MainActivity extends Activity {
// String imageUrl1 = "http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png";
String imageUrl = Uri.encode("http://ioe.edu.np/exam/notices/8560Result Diploma I_I.jpg");
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
ImageView i = (ImageView) findViewById(R.id.imageView1);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
imageUrl).getContent());
i.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Please help me, and also note that I don't have the control over the name of the image files, so I will have to figure out a way so that it loads correctly in the imageview. If I replace the imageUrl with imageUrl1 then the image get loads. But with imageUrl, it seemed to be problem with space being encode to html entities. Please help me with this.
Thank you.