1

当我在使用 WiFi 的设备上运行此应用程序时,它工作正常。但是当我使用移动网络或 3g 时,它会出错。它不适用于移动网络。

我正在使用这段代码:

connection = (HttpConnection) Connector.open(APIURL+ updateConnectionSuffix());     

还有我的 ConnectionTools 类代码:

public String updateConnectionSuffix() {
    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做些什么?

4

2 回答 2

1

试试这个代码。

public static String getConnectionString() {

    String connectionString = null;

    // Simulator behaviour is controlled by the USE_MDS_IN_SIMULATOR
    // variable.
    if (DeviceInfo.isSimulator()) {

        connectionString = ";deviceside=true";
    }

    // Wifi is the preferred transmission method
    else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {

        connectionString = ";interface=wifi";
    }

    // Is the carrier network the only way to connect?
    else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {

        String carrierUid = getCarrierBIBSUid();

        if (carrierUid == null) {
            // Has carrier coverage, but not BIBS. So use the carrier's TCP
            // network

            connectionString = ";deviceside=true";
        } else {
            // otherwise, use the Uid to construct a valid carrier BIBS
            // request

            connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public";
        }
    }

    // Check for an MDS connection instead (BlackBerry Enterprise Server)
    else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {

        connectionString = ";deviceside=false";
    }

    // If there is no connection available abort to avoid hassling the user
    // unnecssarily.
    else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
        connectionString = "none";

    }

    // In theory, all bases are covered by now so this shouldn't be reachable.But hey, just in case ...
    else {

        connectionString = ";deviceside=true";
    }



    return connectionString;
}

/**
 * Looks through the phone's service book for a carrier provided BIBS
 * network
 * 
 * @return The uid used to connect to that network.
 */
private synchronized static String getCarrierBIBSUid() {
    ServiceRecord[] records = ServiceBook.getSB().getRecords();
    int currentRecord;

    for (currentRecord = 0; currentRecord < records.length; currentRecord++) {
        if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
            if (records[currentRecord].getName().toLowerCase()
                    .indexOf("bibs") >= 0) {
                return records[currentRecord].getUid();
            }
        }
    }

    return null;
}

用您的 updateConnectionSuffix() 替换此函数。

于 2012-07-30T15:37:02.337 回答
0

让我解释一下: - 这是使用移动网络 2g 或 3g 任何网络连接”只需复制粘贴即可享受

字符串 url = "vm.b24esolution.com:9090";

最终 HttpConnection 连接 = (HttpConnection) Connector.open("socket://"+url+updateConnectionSuffix()+";apn=rim.net.gprs;tunnelauthusername =;tunnelauthpassword=",Connector.READ_WRITE);

于 2012-07-27T12:52:50.593 回答