Blackberry application, displaying images from the Internet

I am using Blackberry JDE (9000 simulator) and I am wondering if I can display an image from the Internet.

Currently, I see tutorials that use Bitmap.getBitmapResourceto display images that are local to the Blackberry application, but looking at the API, I don't see support for providing web URLs.

Are there any other Blackberry image classes that I can verify? Or is this feature simply not supported?

+3
source share
3 answers

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

See coderholic - Blackberry WebBitmapField

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

+4
source

Here is a sample code 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;
+1
source

If you need a code that did just that (although this post is deprecated, so I assume you don't do this anymore)

Here

0
source

Source: https://habr.com/ru/post/1717654/


All Articles