Blackberry App, display images from Web

2.5k Views Asked by At

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?

3

There are 3 best solutions below

4
On BEST ANSWER

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!

0
On

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

Here

0
On

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;