0

我有以下代码:

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:浏览器运行良好)。怎么了?

4

1 回答 1

1

在获取服务 Book 之前,尝试通过 BIS 进行连接(如果打开了 Blackberry 选项,则使用):

if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_BIS_B) == CoverageInfo.COVERAGE_BIS_B) { connSuffix = ";deviceside=false;ConnectionType=mds-public"; }

于 2012-08-06T13:47:22.400 回答