java - HttpConnection 不适用于 3G

标签 java blackberry java-me blackberry-eclipse-plugin blackberry-jde

我有以下代码:

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 上它不起作用(其他应用程序,例如:浏览器运行良好)。怎么了?

最佳答案

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

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

关于java - HttpConnection 不适用于 3G,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11828822/

相关文章:

java - 如何在黑莓屏幕上渲染网页内容?

java - 在J2me中显示Png图像

java - 在 Firebase android 中的两个日期内搜索子值

java - 使用 Java 从 postgreSQL 检索 inet 数据类型?

java - 在 BlackBerry 设备中禁用背光超时

javascript - 如何滚动到 BlackBerry 网络浏览器中的特定位置?

java - LWUIT ComboBox 弹出主题主题问题

encryption - j2me 中文手机不支持 AESEncoder 类

javascript - 缓存失效和同步 Angular/后端

java - CardLayout 在最后一张卡上关闭