Wednesday, 11 September 2013

downloading images from web in android

downloading images from web in android

Ii am trying to download an image from web and dispaly it in an image
view. the problem is that nothing displays on the screen. I am using the
code below. Thank you!
package com.example.citiestoremember;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class DisplayImage extends Activity {
ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_city);
Intent theIntent = getIntent();
String urlImage = theIntent.getStringExtra("urlImage");
try {
img = (ImageView) findViewById(R.id.urlImage);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new
URL(urlImage).getContent());
img.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

No comments:

Post a Comment