-2

Possible Duplicate:
Show Images from URL in blackberry

Hi am trying to laod an image directly from url in balckberry. there is no option in balckberry to call directly. is something there to do so.kindly guide me.

Community
  • 1
  • 1
Pramodhini
  • 37
  • 5
  • check my answer of this question-http://stackoverflow.com/questions/12049101/show-images-from-url-in-blackberry/12049139#12049139 – Signare Oct 09 '12 at 07:34
  • hai thanks for your code it just worked awesome ,but again how i will cast that to bitmap image.thanks. – Pramodhini Oct 09 '12 at 09:01

1 Answers1

0

There is no shortcut to do so. You need to do it by code.

public static InputStream getInputStream(String url)
{
     InputStream inputStream = null;
     HttpConnection httpConnection = null;
     try
     {                        
         httpConnection = (HttpConnection)Connector.open(url+connectiontype));
         httpConnection.setRequestMethod(HttpConnection.POST);
         final int r=httpConnection.getResponseCode();
         if(r==200)
             inputStream = httpConnection.openDataInputStream();
     }
     catch(final Exception e)
     {
         System.out.println("Error is "+e.getMessage());
     }
     return inputStream;
}

and use getInputStream() like this:

InputStream is=getInputStream(s1);
int length=is.available();
//System.out.print("length ==========="+length);        
byte[] data=new byte[length];

data = IOUtilities.streamToBytes(is);

// code to save image in sd card
saveFile.create();
OutputStream outStream = saveFile.openOutputStream();
outStream.write(data);
outStream.close();
saveFile.close();
is.close();

This code will save image from url.

Nate
  • 30,589
  • 12
  • 76
  • 201
Shashank Agarwal
  • 512
  • 3
  • 12