如何从黑莓手机中的网址加载图片

时间:2012-10-09 07:22:09

标签: blackberry blackberry-simulator blackberry-eclipse-plugin blackberry-jde blackberry-webworks

  

可能重复:
  Show Images from URL in blackberry

我正在尝试直接从balckberry的url中添加图像。在balckberry中没有选项可以直接打电话。是有话要做的。请指导我。

2 个答案:

答案 0 :(得分:0)

没有捷径可以这样做。 你需要通过代码来完成它。

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;
}

并像这样使用getInputStream()

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();

此代码将保存来自网址的图片。

答案 1 :(得分:0)