Code example for URLConnection

Methods: connect, getInputStream

0
    /** Fetch the image specified by the given url */ 
    public static Bitmap fetchImage(URL url) throws IOException {
        InputStream is = null;
        try { 
            URLConnection conn = url.openConnection();
            conn.connect();
            is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is, 16384);
            try { 
                Bitmap bitmap = BitmapFactory.decodeStream(bis);
                return bitmap;
            } finally { 
                bis.close();
            } 
        } finally { 
            if(is != null)
                is.close();
        } 
    } 
 
    /** Read a bitmap from the specified file, scaling if necessary