android view web pictures in gallery
- by bitma
I am new to android, I just finished Hello gallery tutorial, and a web pciture tutorial.
Now I want to know how can I show some web images in gallery?
the hello gallery code is from andorid tutor
this is Web gallery code, I want to load some pictures from web and then show them in gallery, how can I write it?
public class WebGallery extends Activity {
String imageUrl = "http://i.pbase.com/o6/92/229792/1/80199697.uAs58yHk.50pxCross_of_the_Knights_Templar_svg.png";
Bitmap bmImg;
ImageView imView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imView = (ImageView) findViewById(R.id.imview);
imView.setImageBitmap(getRemoteImage(imageUrl));
}
public Bitmap getRemoteImage(String imageUrl) {
try {
URL aURL = new URL(imageUrl);
final URLConnection conn = aURL.openConnection();
conn.connect();
final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
final Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
return bm;
} catch (IOException e) {
Log.d("DEBUGTAG", "Oh noooz an error...");
}
return null;
}
}