0

我正在使用以下代码从服务器下载图像

public Bitmap connectServerForImage(String url) {

    HttpConnection httpConnection = null;
    DataOutputStream httpDataOutput = null;
    InputStream httpInput = null;
    int rc;

    Bitmap bitmp = null;
    try {
     httpConnection = (HttpConnection) Connector.open(url+ ConnectionType.getConnectionType());
      rc = httpConnection.getResponseCode();
     if (rc != HttpConnection.HTTP_OK) {
      throw new IOException("HTTP response code: " + rc);
     }
     httpInput = httpConnection.openInputStream();
     InputStream inp = httpInput;
     byte[] b = IOUtilities.streamToBytes(inp);
     EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
     return hai.getBitmap();

    } catch (Exception ex) {
     System.out.println("URL Bitmap Error........" + ex.getMessage());
    } finally {
     try {
      if (httpInput != null)
       httpInput.close();
      if (httpDataOutput != null)
       httpDataOutput.close();
      if (httpConnection != null)
       httpConnection.close();
     } catch (Exception e) {
      e.printStackTrace();

     }
    }
    return bitmp;
   }

和 ConnetionType 类如下

public class ConnectionType {

  public static String getConnectionType() 
  {        
        String connectionString = null;

        if (DeviceInfo.isSimulator()) 
        {
            connectionString = "";
            return connectionString;
        }         
        else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) 
        {
            connectionString = ";interface=wifi";
            return connectionString;
        }         
        else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) 
        {
            String carrierUid = getCarrierBIBSUid();
            if (carrierUid == null) 
            {               
                connectionString = ";deviceside=true";
                return connectionString;
            } 
            else 
            {
                connectionString=carrierUid;
                return connectionString;

            }
        }           
        else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) 
        {
            connectionString = ";deviceside=false";
            return connectionString;
        }           
        else 
        {

            connectionString = ";deviceside=true";
            return connectionString;
        ]           

  }

 /**
  * Looks through the phone's service book for a carrier provided BIBS
  * network
  *
  * @return The UID used to connect to that network.
  */
 private static String getCarrierBIBSUid() 
 {

    ServiceRecord[] records = ServiceBook.getSB().getRecords();
    int currentRecord;
    for (currentRecord = 0; currentRecord < records.length; currentRecord++) 
    {
        if (records[currentRecord].getCid().toLowerCase().equals("ippp")) 
        {
            if (records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0) 
            {
                //otherwise, use the UID to construct a valid carrier BIB-S     
                String carrierUid= records[currentRecord].getUid();                                     
                String  extension = ";deviceside=false;connectionUID=" + carrierUid + ";ConnectionType=mds-public";                 
                return extension;                   
            }
        }           
    }
    for (currentRecord = 0; currentRecord < records.length; currentRecord++) 
    {
        if(records[currentRecord].getCid().toLowerCase().equals("wptcp"))
        {
            String carrierUid= records[currentRecord].getUid(); 
            String extension = ";ConnectionUID="+carrierUid;
            return extension;
        }
    }       
    return null;
 }       
}

图像在模拟器上显示正常,但是当我在我的设备上运行时没有图像显示。请建议我在哪里失踪。谢谢!!!

4

0 回答 0