J.R.
J.R.

Reputation: 6049

Blackberry App, display images from Web

I'm using the Blackberry JDE (9000 simulator), and am wondering if I can display an image from the web.

Currently, I'm seeing tutorials that use Bitmap.getBitmapResource to display images that are local to the blackberry application, but looking at the API, I'm not seeing any support for giving a web URL.

Are there other Blackberry image classes I can check out? Or is this feature just not supported?

Upvotes: 3

Views: 2567

Answers (3)

Hrvoje
Hrvoje

Reputation: 21

Here is a code example for your problem:

    HttpConnection httpConn = null;
    InputStream inputStream = null;
    int ResponseCode = HttpConnection.HTTP_OK;
    byte[] ResponseData = null;

    try {
        httpConn = (HttpConnection) Connector.open(url, Connector.READ, true); 

        ResponseCode = httpConn.getResponseCode();
        if (ResponseCode == HttpConnection.HTTP_OK) {
            inputStream = httpConn.openInputStream();               
            ResponseData = IOUtilities.streamToBytes(inputStream);
        }
    }
    catch(IOException e){
        throw new IOException("HTTP response code: "
                + ResponseCode);
    }
    finally {
        try {
            inputStream.close();
            inputStream = null;
            httpConn.close();
            httpConn = null;
        }
        catch(Exception e){}
    }
    return ResponseData;

Upvotes: 1

DFTR
DFTR

Reputation: 869

If you want code that made to exactly do this (though this post is old, so I'm guessing you don't anymore)

Here

Upvotes: 0

Maksym Gontar
Maksym Gontar

Reputation: 22775

You can download image using HTTPConnection and InputStream, create EncodedImage from stream and then display it.

See coderholic - Blackberry WebBitmapField

BTW, you can use IOUtilities.streamToBytes() method to read bytes from InputStream directly!

Upvotes: 4

Related Questions