Code example for URLConnection

Methods: connect, getInputStream

0
    public static Bitmap getBitmap(String url) {
        Bitmap bm = null;
        try { 
            URL aURL = new URL(url);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            bm = BitmapFactory.decodeStream(new FlushedInputStream(is));
            bis.close();
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally { 
           // if (httpclient != null) { 
           //     httpclient.close(); 
           // } 
        } 
        return bm;
    }