2012-06-28 2 views
0

내 앱에서 서버에서 여러 이미지를 다운로드해야합니다. 나는 바이트 배열 얻기 위해이 코드를 사용 : "; deviceSide = false를 ConnectionType = MDS - 공개"BlackBerry - 다운로드 한 이미지가 HttpConnection을 사용하여 wifi에서 손상되었습니다.

HttpConnection connection = null; 
InputStream inputStream = null; 
byte[] data = null; 

try 
{ 
//connection = (HttpConnection)Connector.open(url); 
connection = (HttpConnection)Connector.open(url, Connector.READ_WRITE, true); 

     int responseCode = connection.getResponseCode();    
     if(responseCode == HttpConnection.HTTP_OK) 
     { 
      inputStream = connection.openInputStream(); 
      data = IOUtilities.streamToBytes(inputStream); 
      inputStream.close(); 
     }   
     connection.close(); 

     return data; 
    } 
    catch(IOException e) 
    { 
     return null; 
    } 

URL이 접미사로 형성된다 (공백없이)을하고 완벽하게 잘 작동한다.

SIM 카드가없는 휴대 전화에서는 MDS 서버를 통해 인터넷에 연결할 수 없다는 문제가 있습니다. 그것은 좋은 접두사 (우리의 경우 인터페이스 = 무선 랜)를 선택하기 때문에

ConnectionFactory connFact = new ConnectionFactory(); 
    ConnectionDescriptor connDesc; 
    connDesc = connFact.getConnection(url); 

    if (connDesc != null) 
    { 
     final HttpConnection httpConn; 
     httpConn = (HttpConnection)connDesc.getConnection(); 
     try 
     { 
      httpConn.setRequestMethod(HttpConnection.GET); 
      final int iResponseCode = httpConn.getResponseCode(); 
      if(iResponseCode == HttpConnection.HTTP_OK) 
      { 
       InputStream inputStream = null; 
       try{ 
        inputStream = httpConn.openInputStream(); 
        byte[] data = IOUtilities.streamToBytes(inputStream); 
        return data; 
       } 
       catch(Exception e) 
       { 
        e.printStackTrace(); 
        return null; 
       } 
       finally{ 
        try 
        { 
         inputStream.close(); 
        } catch (IOException e) 
        { 
         e.printStackTrace(); 
         return null; 
        } 
       } 
      } 
     } 
     catch (IOException e) 
     { 
      System.err.println("Caught IOException: " + e.getMessage()); 
     } 
    } 
    return null; 

연결이 작동하지만이 또 다른 문제를 만들 : 그래서 우리는 연결 팩토리를 사용하고 BB 그가 원하는대로 선택할 수 있도록 변경되었습니다.

일부 이미지는 잘 다운로드되지 않으며, 일부 이미지는 다운로드되지 않습니다. 일부 이미지는 손상되며, 전화가 와이파이 연결을 사용하여 이미지를 가져 오는 경우에만 손상됩니다.

이 문제를 어떻게 피할 수 있습니까? 어떤 방법으로 연결해야합니까? MDS 공개를 사용하기 위해 사용자가 SIM 카드를 가지고 있는지 확인할 수 있습니까? 여기

는 손상된 이미지의 예입니다

error image http://nsa30.casimages.com/img/2012/06/28/120628033716123822.png

답변

0

interface = wifi를 추가하면 어떻게됩니까? 당신은 KB 문서 아래에 연결된 네트워크 진단 도구를 실행하고 SIM 모든 테스트

http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-OS/ta-p/614822

를 제거 실행할 수 또한 유의하시기 바랍니다 다운로드 큰 파일은 BES/MDS를 통해 MDS에 의해 부과 된 제한이있는 경우. 이 시도 KB 문서 http://supportforums.blackberry.com/t5/Java-Development/Download-large-files-using-the-BlackBerry-Mobile-Data-System/ta-p/44585

0

당신은 범위가 BIS_B (MDS 공개) 충분 있는지 확인할 수 있습니다하지만 당신이 지원하려는 경우 그것은 도움이되지 않습니다 SIM이없는 사용자. 문제가 Wi-Fi 연결과 IOUtilities.streamToBytes() 사이의 비교할 수없는 문제인지 궁금합니다. API documents에서 권장하는 코딩을 시도하십시오.

+0

나는 RIM 클래스 IOUtilities을 사용하고 기본 루프를 사용하지하려고하지만 난없이 무선 랜을 사용할 때 난 아직도이 문제가 발생 SIM 카드. –

1

아래의 검토 확인하십시오 :

public static String buildURL(String url) { 
    String connParams = ""; 


     if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) { 
      connParams = ";interface=wifi"; //Connected to a WiFi access point. 
     } else { 
      int coverageStatus = CoverageInfo.getCoverageStatus(); 
      // 
      if ((coverageStatus & CoverageInfo.COVERAGE_BIS_B) == CoverageInfo.COVERAGE_BIS_B) { 
       connParams = ";deviceside=false;ConnectionType=mds-public"; 
      } else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) { 
       // Have network coverage and a WAP 2.0 service book record 
       ServiceRecord record = getWAP2ServiceRecord(); 
       // 
       if (record != null) { 
        connParams = ";deviceside=true;ConnectionUID=" + record.getUid(); 

       } else { 
        connParams = ";deviceside=true"; 
       } 
      } else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) { 
       // Have an MDS service book and network coverage 
       connParams = ";deviceside=false"; 
      } 
     } 

     Log.d("connection param"+url+connParams); 

    // 
    return url+connParams; 
} 

private static ServiceRecord getWAP2ServiceRecord() { 
    String cid; 
    String uid; 
    ServiceBook sb = ServiceBook.getSB(); 
    ServiceRecord[] records = sb.getRecords(); 
    // 
    for (int i = records.length -1; i >= 0; i--) { 
     cid = records[i].getCid().toLowerCase(); 
     uid = records[i].getUid().toLowerCase(); 
     // 
     if (cid.indexOf("wptcp") != -1 
       && records[i].getUid().toLowerCase().indexOf("wap2") !=-1 
       && uid.indexOf("wifi") == -1 
       && uid.indexOf("mms") == -1) { 
      return records[i]; 
     } 
    } 
    // 
    return null; 
} 
관련 문제