2011-12-22 17 views
0

我在将应用程序部署到设备时连接到托管我的Web服务的服务器时出现问题。当我使用以下连接参数时会发生这种情况:BlackBerry Java java.io.IOException:无法传输

}else if(TransportTypes[i]== TransportInfo.TRANSPORT_TCP_CELLULAR){ 
      String carrierUid = getCarrierBIBSUid(); 
       if(carrierUid == null) { 
        ConnectionParameter = ";deviceside=true"; 
       } 
       else{ 
        **ConnectionParameter = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public**"; 
       } 

      break; 
     } 


public static String getCarrierBIBSUid(){ 

    ServiceBook sb = ServiceBook.getSB(); 
    ServiceRecord[] records = sb.findRecordsByCid("WPTCP"); 
    String uid = null; 

    for(int i=0; i < records.length; i++) 
    { 
     //Search through all service records to find the 
     //valid non-Wi-Fi and non-MMS 
     //WAP 2.0 Gateway Service Record. 
     if (records[i].isValid() && !records[i].isDisabled()) 
     { 

      if (records[i].getUid() != null && records[i].getUid().length() != 0) 
      { 
       if ((records[i].getUid().toLowerCase().indexOf("wifi") == -1) && 
        (records[i].getUid().toLowerCase().indexOf("mms") == -1)) 
       { 
         uid = records[i].getUid(); 
         break; 
       } 
      } 
     } 
    } 
    return uid; 

} 

在模拟器上一切正常。

if(TransportTypes[i]== TransportInfo.TRANSPORT_TCP_WIFI){ 
      ConnectionParameter = ";interface=wifi"; 
      break; 
     } 

或只是:使用WiFi时

一切还曾设备和模拟器上都精细

ConnectionParameter = ";interface=wifi"; 

任何一个有什么线索可能是这种方法的问题?

+0

你是指你已添加**的行吗? – jprofitt 2011-12-22 13:17:04

+0

它使用直接tcp。你有没有设置APN设置? – rfsk2010 2011-12-22 13:56:53

+0

是Rihan,它使用TCP但设置APN是我现在的问题。你有线索吗? – 2011-12-22 14:38:09

回答

0

那么,我找到了解决问题的方法。尽管APN设置仍然需要使用TCP直接通道。在使用之前,我连续检查了最强的可用频道。下面

是我的代码的摘录:

public static String getConnParams() { 
    String ConnectionParameter ="" ; 
    int TransportTypes[] = TransportInfo.getAvailableTransportTypes(); 
    int wifi=0; 
    int wap2=0; 
    int BIS=0; 
    int MDS=0; 
    for(int i=0; i<TransportTypes.length; i++){ 
     if(TransportTypes[i]== TransportInfo.TRANSPORT_TCP_WIFI){ 
     wifi = TransportInfo.TRANSPORT_TCP_WIFI ; 
     }else if(TransportTypes[i]== TransportInfo.TRANSPORT_WAP2){ 
     wap2 = TransportInfo.TRANSPORT_WAP2; 
     }else if(TransportTypes[i]== TransportInfo.TRANSPORT_BIS_B ){ 
      BIS = TransportInfo.TRANSPORT_BIS_B; 
     }else if(TransportTypes[i]== TransportInfo.TRANSPORT_MDS){ 
      MDS = TransportInfo.TRANSPORT_MDS; 
     } 
    } 

    if(wifi!=0 && TransportInfo.hasSufficientCoverage(wifi)){ 
     ConnectionParameter = ";interface=wifi"; 
     return ConnectionParameter; 
    }else if(wap2 !=0 &&TransportInfo.hasSufficientCoverage(wap2)){ 
     String carrierUid = getCarrierBIBSUid(); 
     if(carrierUid == null) { 
      ConnectionParameter = ";deviceside=true"; 
     } 
     else{ 
      ConnectionParameter = ";deviceside=true;connectionUID="+carrierUid; 
     } 
     return ConnectionParameter; 
    }else if(BIS !=0 && TransportInfo.hasSufficientCoverage(BIS)){ 
     ConnectionParameter = ";deviceside=false"; 
     return ConnectionParameter; 
    }else if(MDS !=0 && TransportInfo.hasSufficientCoverage(MDS)){ 
     ConnectionParameter = ";deviceside=false"; 
     return ConnectionParameter; 
    }else{ 
     ConnectionParameter = ";deviceside=true";  
     return ConnectionParameter; 
    } 


} 

除了你会真正找到下面的链接有用: Creating a BlackBerry HTTP Connection – Tutorial

谢谢大家的建议。

相关问题