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.
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.
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.