0

工作,我有以下代码:的HttpConnection不与3G

HttpConnection httpCon = null; 
InputStream fileIn = null; 
try 
{ 
    httpCon = (HttpConnection) Connector.open(url + getConnectionSuffix(), Connector.READ); 
    httpCon.setRequestMethod(HttpConnection.GET); 
    } 
    catch (Exception e) 
    { 
     ....... 
    } 
    ............. 

private String getConnectionSuffix() 
{ 
    String connSuffix = ""; 
    if (DeviceInfo.isSimulator()) 
    { 
     connSuffix = ";deviceside=true"; 
    } 
    else if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) && 
      RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) 
    { 
     connSuffix=";interface=wifi"; 
    } 
    else 
    { 
     String uid = null; 
     ServiceBook sb = ServiceBook.getSB(); 
     ServiceRecord[] records = sb.findRecordsByCid("WPTCP"); 
     for (int i = 0; i < records.length; i++) 
     { 
      if (records[i].isValid() && !records[i].isDisabled()) 
      { 
       if (records[i].getUid() != null && 
        records[i].getUid().length() != 0) 
       { 
        if ((records[i].getCid().toLowerCase().indexOf("wptcp") != -1) && 
         (records[i].getUid().toLowerCase().indexOf("wifi") == -1) && 
         (records[i].getUid().toLowerCase().indexOf("mms") == -1)) 
        { 
         uid = records[i].getUid(); 
         break; 
        } 
       } 
      } 
     } 
     if (uid != null) { 
      // WAP2 Connection 
      connSuffix = ";ConnectionUID="+uid; 
     } else { 
      connSuffix = ";deviceside=true"; 
     } 
    } 
    return connSuffix; 
} 

但互联网并不总是工作。在3G上它不起作用(其他应用程序,对于exp:浏览器效果很好)。哪里不对?

+0

看看这个链接http://stackoverflow.com/questions/11670246/httpconnection-connect-with-mobile-network-or-3g/11724735#11724735 – 2012-08-06 13:51:09

+0

什么是你的traget os?如果它是5+,则可以使用ConnectionFactory而不是手动检测连接传输。 – 2012-08-07 05:06:27

回答

1

之前得到服务书,试图通过BIS连接(如果使用黑莓选项打开):

IF((CoverageInfo.getCoverageStatus()& CoverageInfo.COVERAGE_BIS_B)== CoverageInfo.COVERAGE_BIS_B){ connSuffix =“; deviceside = false; ConnectionType = mds-public”; }